Пример #1
0
 private void DestroyPublisherSocket()
 {
     if (publisherSocket != null)
     {
         publisherSocket.Close();
     }
 }
Пример #2
0
 public void Dispose()
 {
     lock (_lockObj)
     {
         try
         {
             if (SendEndOfFlag)
             {
                 // 发送结束标志
                 foreach (string topic in strTopics)
                 {
                     _publisher.SendMoreFrame(topic).SendFrame(MyFuncOfFlag.EndOfFlag);
                 }
                 foreach (string topic in dataTopics)
                 {
                     _publisher.SendMoreFrame(topic).SendFrame(MyFuncOfFlag.EncodeFlag());
                 }
             }
             _publisher.Close();
             _publisher.Dispose();
             dataTopics.Clear();
             strTopics.Clear();
         }
         catch { }
     }
 }
Пример #3
0
    // Client thread which does not block Update()
    void NetMQClient()
    {
        AsyncIO.ForceDotNet.Force();
        NetMQConfig.ManualTerminationTakeOver();
        NetMQConfig.ContextCreate(true);

        //string msg;
        var timeout = new System.TimeSpan(0, 0, 1); //1sec

        Debug.Log("Connect to the server.");

        pubSocket = new PublisherSocket();
        pubSocket.Options.ReceiveHighWatermark = 0;
        pubSocket.Connect("tcp://192.168.1.122:55556");

        bool is_connected = true;

        while (is_connected && stop_thread_ == false)
        {
            pubSocket.TrySendFrame(timeout, final);
        }

        pubSocket.Close();
        Debug.Log("ContextTerminate.");
        NetMQConfig.ContextTerminate();
        NetMQConfig.Cleanup();
    }
Пример #4
0
    protected override void Run()
    {
        AsyncIO.ForceDotNet.Force(); // this line is needed to prevent unity freeze after one use, not sure why yet

        using (SUB = new SubscriberSocket())
            using (PUB = new PublisherSocket())
                using (REQ = new RequestSocket()) {
                    SUB.Connect("tcp://localhost:5555");
                    SUB.Subscribe("");

                    PUB.Connect("tcp://localhost:5556");

                    REQ.Connect("tcp://localhost:5557");

                    Debug.Log("Connected: Receiving Messages");

                    while (Running)
                    {
                        /*Receive continuos Slicer data*/
                        string msg = SUB.ReceiveFrameString();

                        /*Send continuos Unity data*/
                        var bytes = new byte[dataPackage.t.Length * 4];
                        System.Buffer.BlockCopy(dataPackage.t, 0, bytes, 0, bytes.Length);
                        PUB.SendFrame(bytes);

                        /*Request volume data once*/
                        if (reqestData)
                        {
                            REQ.SendFrame("volume");
                            string msg2 = REQ.ReceiveFrameString();
                            Debug.Log(msg2);

                            byte[] file = System.IO.File.ReadAllBytes(msg2);
                            Debug.Log(file.Length);

                            int     d1     = System.BitConverter.ToInt32(file, 0);
                            int     d2     = System.BitConverter.ToInt32(file, 4);
                            int     d3     = System.BitConverter.ToInt32(file, 8);
                            float[] volume = new float[d1 * d2 * d3];
                            System.Buffer.BlockCopy(file, 12, volume, 0, volume.Length * sizeof(float));

                            string s = d1 + " " + d2 + " " + d3 + " : ";
                            //for (int i = 0; i < volume.Length; ++i) s += volume[i] + " ";
                            Debug.Log(s);

                            reqestData = false;
                        }

                        /*60fps*/
                        System.Threading.Thread.Sleep(16);
                    }

                    SUB.Close();
                    PUB.Close();
                    REQ.Close();
                }
        NetMQConfig.Cleanup();
    }
        public void Disconnect()
        {
            PublisherSocket?.Close();
            PublisherSocket?.Dispose();

            SubscriberSocket?.Close();
            SubscriberSocket?.Dispose();
        }
Пример #6
0
 protected override void Clean()
 {
     SUB.Close();
     PUB.Close();
     REQ.Close();
     NetMQConfig.Cleanup();
     AsyncIO.ForceDotNet.Force();
 }
Пример #7
0
 void OnApplicationQuit()
 {
     quite = true;
     if (pubSocket != null)
     {
         pubSocket.Close();
     }
 }
Пример #8
0
 public void Stop()
 {
     if (!_feederSocket.IsDisposed)
     {
         _feederSocket.Close();
         _feederSocket.Dispose();
     }
 }
Пример #9
0
 public void Stop()
 {
     if (Started)
     {
         Started = false;
         Server.Close();
     }
 }
Пример #10
0
 public void Quit()
 {
     isBinded = false;
     if (pubSocket != null)
     {
         pubSocket.Unbind(BindAddres);
         pubSocket.Close();
         pubSocket = null;
     }
 }
Пример #11
0
        public void Stop()
        {
            _cancel.Cancel();

            _heartbeatSocket.Close();
            _heartbeatSocket.Dispose();

            _publisherSocket.Close();
            _publisherSocket.Dispose();
        }
Пример #12
0
        public async Task Stop()
        {
            _isConnected.OnCompleted();
            _disconnected.Dispose();

            _publishMarketUpdates.Close();
            _publishMarketUpdates.Dispose();

            await Cleanup();
        }
 /// <summary>
 /// Stops MQ Publisher once and for all
 /// </summary>
 public void Stop()
 {
     if (Publisher != null)
     {
         Publisher.Unbind("tcp://" + IP + ":" + Port.ToString());
         Publisher.Close();
         Publisher.Dispose();
         Publisher = null;
     }
 }
Пример #14
0
        // --------------------------------------------------------
        // Button handling
        // --------------------------------------------------------

        // Cleanup stuff when closing the window
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (processing_thread != null)
            {
                // Stop capture and tracking
                thread_running = false;
                processing_thread.Join();
            }
            // Added by Huang
            pubSocket.Close();
        }
Пример #15
0
        public bool Stop()
        {
            _reader.StopReadForever();
            _reader.CloseDevice();
            _pubsock.Close();
            _socketServer.Stop();

            _log.Info("CardReaderService Stopped");

            return(true);
        }
Пример #16
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (null != WorkThread && WorkThread.IsAlive)
            {
                EventStop.Set();
                WorkThread.Join();
                WorkThread = null;
            }

            Sock.Close();
            Sock = null;
        }
Пример #17
0
 protected override void disconnectClose()
 {
     if (sender != null)
     {
         // TODO: check first if closed
         sender.Disconnect("tcp://" + IP + ":" + Port);
         sender.Close();
         sender.Dispose();
         sender = null;
     }
     //NetMQConfig.Cleanup();
 }
Пример #18
0
        protected override Task DestroyInternal()
        {
            _cancel.Cancel();

            _state.OnCompleted();
            _state.Dispose();

            _publisherSocket.Close();
            _publisherSocket.Dispose();

            return(Task.CompletedTask);
        }
Пример #19
0
        public void Stop()
        {
            if (_publisher != null)
            {
                _publisher.SendReady -= _publisher_SendReady;
                _publisher.Close();
            }

            if (_poller != null)
            {
                _poller.Stop();
                _poller.Remove(_publisher);
            }
        }
Пример #20
0
        protected async override Task DestroyInternal()
        {
            _cancel.Cancel();

            _state.OnCompleted();
            _state.Dispose();

            _publisherSocket.Close();
            _publisherSocket.Dispose();

            _heartbeatPoller.Stop();

            await WaitForWorkProceduresToComplete(_heartbeatProc);

        }
 public void Dispose()
 {
     if (subscriberDelegates != null)
     {
         lock (subscriberDelegates)
         {
             subscriberDelegates = new Dictionary <string, HashSet <Action <string, object[]> > >();
         }
     }
     foreach (var worker in workers)
     {
         worker.CancelAsync();
     }
     publisherSocket.Close();
 }
Пример #22
0
        public void Destroy()
        {
            if (waitingOnConnection)
            {
                requestController.OnConnected -= DelayedSetup;
            }

            if (isSetup)
            {
                if (publisherSocket != null)
                {
                    publisherSocket.Close();
                }
            }
        }
Пример #23
0
        private void PublishEntry()
        {
            using (PublisherSocket publisher = new PublisherSocket())
            {
                string endpoint = "tcp://*:" + ModPub.port;

                try
                {
                    publisher.Bind(endpoint);
                }
                catch (Exception err)
                {
                    Logging.logger.Error(ModName + " bind socket failed " + endpoint + " " + err.Message);
                    throw (err);
                }

                PubRM.pubsock = publisher;
                string d = string.Empty;
                PubRM.Working = true;
                while (PubRM.Running)
                {
                    d = string.Empty;

                    //string received = serverSocket.ReceiveFrameString();
                    try
                    {
                        d = Entry4GetPubData();
                    }
                    catch (Exception err)
                    {
                        Logging.logger.Error(err.Message);
                        DelayTime();
                        continue;
                    }

                    if (d != null)
                    {
                        publisher.SendFrame(d);
                    }

                    DelayTime();
                }
                PubRM.Working = false;
                publisher.Close();
            }
        }
Пример #24
0
        public void Stop()
        {
            _cancel.Cancel();

            _poller.Stop();

            _heartbeat.Close();
            _heartbeat.Dispose();

            _publishStateUpdate.Close();
            _publishStateUpdate.Dispose();

            _subscribeToUpdates.Close();
            _subscribeToUpdates.Dispose();

            _stateRequest.Close();
            _stateRequest.Dispose();
        }
Пример #25
0
        public void kill()
        {
            app_exit = true;

            if (thread != null)
            {
                thread.Abort();
                thread = null;
            }

            if (publisher != null)
            {
                publisher.Close();
            }

            if (subscriber != null)
            {
                subscriber.Close();
            }
        }
Пример #26
0
    public void killSetup()
    {
        app_exit_sub = true;

        if (subscriber != null)
        {
            subscriber.Close();
        }

        if (publisher != null)
        {
            publisher.Close();
        }

        if (sub_thread != null)
        {
            sub_thread.Abort();
        }

        GC.Collect();
        GC.WaitForPendingFinalizers();
    }
Пример #27
0
 private void StopPublishing()
 {
     pubSocket.Close();
     NetMQConfig.Cleanup();
 }
Пример #28
0
    //private void FixedUpdate()
    //{
    //    string recvStr;
    //  if (_sub.TryReceiveFrameString(out recvStr))
    //  {
    //       var recvJson = JsonConvert.DeserializeObject<Dictionary<string, string>>(recvStr);
    //       //if (int.Parse(recvJson["ID"]) != id) return;
    //       var forceX = float.Parse(recvJson["force_x"]);
    //       var forceY = float.Parse(recvJson["force_y"]);
    //       var forceZ = float.Parse(recvJson["force_z"]);
    //       _hip.AddRelativeForce(forceX, forceY, -forceZ);    //negative z because conversion from right-hand to left-hand coordinates
    //   }
    // }

    private void OnDestroy()
    {
        _pub.Close();
        _sub.Close();
    }
Пример #29
0
        private void FanInPubEntry(object n)
        {
            FansInPubRun f;
            string       name = (string)n;

            if (FunInPubRM.ContainsKey(name))
            {
                f = FunInPubRM[name];
            }
            else
            {
                Logging.logger.Error("FunInPubEntry get name failed " + name);
                return;
            }

            PullSocket      pull = new PullSocket();
            PublisherSocket pub  = new PublisherSocket();
            string          le   = "tcp://" + f.PullPoint.ip + ":" + f.PullPoint.port;
            string          pe   = "tcp://*:" + f.PubPoint.port;

            try
            {
                pull.Bind(le);
                pub.Bind(pe);
                f.pull = pull;
                f.pub  = pub;
            }
            catch (Exception err)
            {
                Logging.logger.Error(ModName + " bind funin socket failed " + le + " " + pe + " " + err.Message);
                throw (err);
            }
            string str;
            string outdata;
            bool   result;

            f.Working = true;
            while (f.Running)
            {
                str    = string.Empty;
                result = pull.TryReceiveFrameString(out str);

                outdata = string.Empty;
                if (result == true)
                {
                    try
                    {
                        outdata = Entry4FanInPubData(name, str);

                        if (outdata != null)
                        {
                            pub.SendFrame(outdata);
                        }
                    }
                    catch (Exception err)
                    {
                        Logging.logger.Error("exception occur " + name + err.Message);
                        continue;
                    }
                }

                DelayTime();
            }
            f.Working = false;
            pull.Close();
            pub.Close();
            return;
        }
Пример #30
0
        private void SingleSubPubEntry(object pubname)
        {
            string pn = (string)pubname;


            if (SubPubRM.ContainsKey(pn))
            {
                SubPubRun spr = SubPubRM[pn];
                using (PublisherSocket publisher = new PublisherSocket())
                    using (SubscriberSocket subsciber = new SubscriberSocket())
                    {
                        //List<string> EndPointl = new List<string>();
                        string e = string.Empty;
                        foreach (Point p in spr.subs)
                        {
                            e = "tcp://" + p.ip + ":" + p.port;
                            subsciber.Connect(e);
                            subsciber.Subscribe("");
                        }

                        e = "tcp://*:" + spr.pub.port;
                        try
                        {
                            publisher.Bind(e);
                        }
                        catch (Exception err)
                        {
                            Logging.logger.Error(ModName + " bind socket failed " + " " + err.Message);
                            throw (err);
                        }
                        spr.pubsock = publisher;
                        spr.subsock = subsciber;
                        string received;
                        string pubdata;
                        bool   result;
                        spr.Working = true;
                        while (spr.Running)
                        {
                            received = string.Empty;
                            result   = subsciber.TryReceiveFrameString(out received);

                            if (result == true)
                            {
                                pubdata = string.Empty;
                                try
                                {
                                    pubdata = this.Entry4SubPubData(spr.pub.name, received);
                                }
                                catch (Exception err)
                                {
                                    Logging.logger.Error(err.Message);
                                    pubdata = string.Empty;
                                    throw (err);
                                }
                                if (pubdata != null)
                                {
                                    publisher.SendFrame(pubdata);
                                }
                            }

                            DelayTime();
                        }
                        spr.Working = false;
                        publisher.Close();
                        subsciber.Close();
                    }
            }
            else
            {
                Logging.logger.Error("SingleSubPubEntry can not get pubname " + pubname);
                return;
            }
        }