Giter Club home page Giter Club logo

unity-zeromq-example's Introduction

An example of Unity 3D 2017 works with ZeroMQ

Environment

Unity 2017.1

Python 3.6.0

Tested on macOS Sierra Tested on Windows 10

What's in this demo

Python scripts:

C# scripts:

Scene:

How to run

First start 2 python scripts (in seperate shell sessions):

./Python/server.py
./Python/client.py

Then start play mode of main demo scene in Unity Editor.

You should see the box jump around according to commands sent by python server script and python client script should be able to receive the location update of the same box.

unity-zeromq-example's People

Contributors

valkjsaaa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unity-zeromq-example's Issues

how to create project from scratch?

Hi, I was able to use zmq from your demo(git clone) but I am not sure how to set up from the new project.

I am getting "The type or namespace name 'NetMQ' could not be found."

Little help?

Thanks alot!!!!

Why in unity 2017.3.1 not work?

Why in unity 2017.3.1 does not work? the same code in unity 2017.1 ... works well.

 if (!subSocket.TryReceiveFrameString(out frameString)) continue;
  Debug.Log(frameString);

In version 2017.3.1 "frameString" always is null.

Does anyone know what has changed?

Not working on Android

Hello,
I successfully used Unity ZMQ in Editor, but I failed using it on Android.
After trying to connect, I'm getting the following messages:
2019-04-26 19:50:56.777 27894-28073/com.WhySoSeriousGames.PupilConnect D/Unity: Unable to lookup library path for 'kernel32.dll', native render plugin support disabled. 2019-04-26 19:50:56.779 27894-28073/com.WhySoSeriousGames.PupilConnect E/Unity: Unable to find kernel32.dll 2019-04-26 19:50:56.868 27894-28073/com.WhySoSeriousGames.PupilConnect D/Unity: Unable to lookup library path for 'MonoPosixHelper', native render plugin support disabled. 2019-04-26 19:50:56.870 27894-28073/com.WhySoSeriousGames.PupilConnect E/Unity: Unable to find MonoPosixHelper

I have the following .Net settings in Unity:
Scripting Runtime Version: .NET 4.x Equivalent
Scripting Backend: Mono
API Compatability Level: .NET 4.x
image

Any suggestions?

Publish from C#?

Do you have any examples of how to publish from C#? I've tried everything I can for about 5 hrs now and nothing shows up Python client. Request/Response works ok and Python->Unity Pub/Sub works.

Unity 2018 Client with Bind and Server Connect (from computer to computer not working)

Hi, I tried to change the code with unity 2018 and I noticed that everything works correctly in localhost but when I try to modify the code by making the client bind and the server connect locally it works but from computer to computer no . Can you help me?

` public class NetMqListenerTest
{
private readonly Thread _listenerWorker;

private bool _listenerCancelled;

public delegate void MessageDelegate(string message);

private readonly MessageDelegate _messageDelegate;

private readonly ConcurrentQueue<string> _messageQueue = new ConcurrentQueue<string>();

private void ListenerWork()
{
    AsyncIO.ForceDotNet.Force();
    Debug.Log(" ListenerWork");

    using (var subSocket = new SubscriberSocket())
    {
        Debug.Log(" SubscriberSocket");

        //subSocket.Options.ReceiveHighWatermark = 1000;
        subSocket.Bind("tcp://192.168.2.121:9367");
       // subSocket.Bind("tcp://localhost:9367");
      //  subSocket.Connect("tcp://localhost:12345");
        subSocket.Subscribe("");
        
        Debug.Log(" subSocket.Subscribe");
        Debug.Log("_listenerCancelled : "+_listenerCancelled);

        while (!_listenerCancelled)
        {
            string frameString;
           // Debug.Log("frameString : "+subSocket.TryReceiveFrameString(out frameString));
            Debug.Log("frameString :");
            if (!subSocket.TryReceiveFrameString(out frameString)) continue;
            Debug.Log(frameString);
            _messageQueue.Enqueue(frameString);
        }
        subSocket.Close();
        Debug.Log(" Close");

    }
    NetMQConfig.Cleanup();
    Debug.Log(" Cleanup");

}

public void Update()
{
    while (!_messageQueue.IsEmpty)
    {
        string message;
        if (_messageQueue.TryDequeue(out message))
        {
            _messageDelegate(message);
        }
        else
        {
            break;
        }
    }
}

public NetMqListenerTest(MessageDelegate messageDelegate)
{
    _messageDelegate = messageDelegate;
    _listenerWorker = new Thread(ListenerWork);
    Debug.Log(" NetMqListenerTest _listenerWorker");

}

public void Start()
{
    _listenerCancelled = false;
    _listenerWorker.Start();
    Debug.Log(" _listenerWorker Start");

}

public void Stop()
{
    _listenerCancelled = true;
    _listenerWorker.Join();
    Debug.Log(" _listenerWorker Stop");

}

}

public class Test : MonoBehaviour
{
private NetMqListenerTest _netMqListener;

private void HandleMessage(string message)
{
    Debug.Log("Message: "+message);
}

private void Start()
{
    Debug.Log("Start");
    _netMqListener = new NetMqListenerTest(HandleMessage);
    _netMqListener.Start();
    Debug.Log(" _netMqListener Start");

}

private void Update()
{
    _netMqListener.Update();
}

private void OnDestroy()
{
    _netMqListener.Stop();
}

} `

server:
`#! /usr/local/bin/python3
import zmq
import time
import random
context = zmq.Context()
socket = context.socket(zmq.PUB)
hostname = "192.168.2.121"
socket.connect('tcp://%s:9367' % hostname)

while True:
message = str(random.uniform(-1.0, 1.0)) + " " + str(random.uniform(-1.0, 1.0)) + " " + str(random.uniform(-1.0, 1.0))
socket.send_string(message)
print(message)
time.sleep(1)`

Suggestions on sync-by-frame communication between Unity and ZeroMQ?

I'm currently working on a project which have a sync-by-frame behavior between server (Unity) and Client(python). The intuitive implementation with non-threading zmq leads unity editor to freeze after every time stop playing. I've tried put NetMQConfig.cleanup on several places (onDestory/onApplicationQuit) but non of those works. For the solution of two threads with mutex is a little bit wierd (since the model apprently works on a single thread behavior, is it?) and is my last will to accomplish. Is there any suggestion on how to deal with it? Thanks very much!


The basic pattern would be: unity runs one frame, send data to python, python send back intructions for the next step, and unity executes intructions on the next frame.

Where do you learn about unity ZeroMQ?

There is learning for ZeroMQ Python and C# but they are not specific to unity and I saw you use AsyncIO as well which is confusing for me because I'm not good at network programming.
If I want to build a request-reply model but I want python to be the server instead of C#, how do I accomplish this task?

Python = server
C# = client

The idea is, I want to make some computation in python and return value to caller from C#. E.g. run machine learning model on an image sent by unity webcam and return the prediction to unity.
The time it takes to run the computation might be long so unity should not wait for python to finish. Python have to callback unity later.
Please give materials for me to learn about ZeroMQ request-reply model in unity. Any suggestions are appreciated!

Unity 5.6 compatibility

I'm trying to use this with Unity 5.6 and it doesn't work. As far as I can tell, the only reason is because it uses ConcurrentQueue which was added in .NET 4.0 and the version of Mono in Unity 5.6 is roughly equivalent to .NET 3.5. Do you have any plans to make a version compatible with 5.6, or does anyone have any suggestions on something that could replace ConcurrentQueue? I'm new to C# so I don't know all the various structures yet.

How do you get the latest stable NetMq release binary?

As the title said, how do you get .dll files that are required for using NetMQ?

I read the document of NetMq and it said that I have to install via NuGet. But I tried installing a package there before and Unity didn't recognize it.

great

Hello,
this is great,

connect SUMO to Unity3D

Hello, how can I connect SUMO to Unity3D? I have cloned your projects and simulation is running but unfortunately connection between Unity3D with SUMO is not working.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.