void TTimeOut(Object obj) { ConsoleEx.DebugLog("HeartBeat Server Sock is timeout.", ConsoleEx.RED); if (TimeOut != null) { TimeOut.Change(Timeout.Infinite, Timeout.Infinite); } if (OnDisconnected != null) { OnDisconnected(); } if (poller != null) { if (poller.IsStarted) { poller.CancelAndJoin(); } poller.Dispose(); } if (respSocket != null) { respSocket.Unbind(BindingAddress); respSocket.Close(); } ConsoleEx.DebugLog("HeartBeat Server socket is Connecting...", ConsoleEx.RED); var context = Core.ZeroMQ; respSocket = context.CreateResponseSocket(); respSocket.Options.SendHighWatermark = EngCfg.HighWatermark; respSocket.Options.ReceiveHighWatermark = EngCfg.HighWatermark; //生成通讯地址和协议方式 BindingAddress = BindAddr(typeof(HeartBeatServer)); respSocket.Bind(BindingAddress); respSocket.ReceiveReady += Server_ReceiveReady; poller.AddSocket(respSocket); ThreadPool.QueueUserWorkItem((ob) => { poller.PollTillCancelled(); }); }
public void Stop() { _running = false; if (_activeEndPoint != null) { _activeResponder.Unbind(_activeEndPoint); _activeResponder.Close(); } }
public void TestRebindSamePort() { int port; using (var response = new ResponseSocket()) { port = response.BindRandomPort("tcp://127.0.0.1"); response.Unbind(); } using (var response = new ResponseSocket()) { response.Bind($"tcp://127.0.0.1:{port}"); response.Unbind(); } }
public void Quit() { if (poller != null) { bool started = poller.IsStarted; if (started) { poller.CancelAndJoin(); } poller.Dispose(); } if (respSocket != null) { respSocket.Unbind(BindingAddress); respSocket.Close(); respSocket = null; } }
public void Start() { sub.ActiveMonitor = true; //Thread montitorThread = new Thread(sub.MontitorLister); while (socket == null || sub.IsListenerPresent()) { if (socket == null) { socket = new ResponseSocket(); socket.Bind(Address); //montitorThread.Start(); } if (socket.TryReceiveFrameString(TimeSpan.FromSeconds(20), out string msg)) { if (!ProcessMessage(msg)) { break; } } } sub.ActiveMonitor = false; socket.Unbind(Address); socket.Dispose(); }
private void dataServer() { AsyncIO.ForceDotNet.Force(); using (var dataSender = new ResponseSocket()) { dataSender.Bind("tcp://*:5565"); Debug.Log("Enter while.. "); while (isRunning) { string message = dataSender.ReceiveFrameString(); print("Got request message: " + message); // re-run scene iteration if true if (doGatherOnRequest) { gatherSceneData(); } switch (message) { case "header": print("Send Header.. "); dataSender.SendFrame(headerByteData); print(string.Format(".. Nodes ({0} bytes) sent ", headerByteData.Length)); break; case "nodes": print("Send Nodes.. "); dataSender.SendFrame(nodesByteData); print(string.Format(".. Nodes ({0} bytes) sent ", nodesByteData.Length)); break; case "objects": print("Send Objects.. "); dataSender.SendFrame(objectsByteData); print(string.Format(".. Objects ({0} bytes) sent ", objectsByteData.Length)); break; case "textures": print("Send Textures.. "); dataSender.SendFrame(texturesByteData); print(string.Format(".. Textures ({0} bytes) sent ", texturesByteData.Length)); break; #if TRUNK case "materials": print("Send Materials.. "); dataSender.SendFrame(materialsByteData); print(string.Format(".. Materials ({0} bytes) sent ", materialsByteData.Length)); break; #endif default: break; } } dataSender.Unbind("tcp://127.0.0.1:5565"); dataSender.Close(); dataSender.Dispose(); } //NetMQConfig.Cleanup(); }