Last active
June 29, 2020 15:43
-
-
Save somdoron/6f9184092f16624c65de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Client : MonoBehaviour | |
{ | |
private SubscriberSocket m_subscriber; | |
private NetMQContext m_context; | |
// Use this for initialization | |
void Start() | |
{ | |
ForceDotNet.Force(); | |
m_context = NetMQContext.Create(); | |
m_subscriber = m_context.CreateSubscriberSocket(); | |
m_subscriber.Options.Linger = TimeSpan.Zero; | |
m_subscriber.Subscribe(""); | |
m_subscriber.Connect("tcp://127.0.0.1:55561"); | |
Debug.Log("Connected"); | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
string message; | |
while (m_subscriber.TryReceiveFrameString(out message)) | |
{ | |
Debug.Log("Received"); | |
} | |
} | |
void OnApplicationQuit() | |
{ | |
m_subscriber.Dispose(); | |
m_context.Dispose(); | |
Debug.Log("Exit"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Server : MonoBehaviour { | |
private NetMQContext m_context; | |
private PublisherSocket m_publisher; | |
private int m_count = 0; | |
// Use this for initialization | |
void Start () { | |
ForceDotNet.Force(); | |
m_context = NetMQContext.Create(); | |
m_publisher = m_context.CreatePublisherSocket(); | |
m_publisher.Options.Linger = TimeSpan.Zero; | |
m_publisher.Bind("tcp://127.0.0.1:55561"); | |
Debug.Log("Bound"); | |
} | |
// Update is called once per frame | |
void Update () { | |
m_count++; | |
if (m_count % 200 == 0) | |
{ | |
m_publisher.SendFrame(m_count.ToString()); | |
Debug.Log("Published"); | |
} | |
} | |
void OnApplicationQuit() | |
{ | |
m_publisher.Dispose(); | |
m_context.Dispose(); | |
Debug.Log("Exit"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment