Exemple #1
0
        public string Request(string service, string msg, int timeoutmsec)
        {
            string      resp    = string.Empty;
            LinkAddress address = config.ReqRep.FindLinkAddress(service);

            if (address == null)
            {
                return(resp);
            }

            bool   pollResult = false;
            string requestId  = Guid.NewGuid().ToString();

            using (NetMQContext context = NetMQContext.Create())
            {
                NetMQSocket client = context.CreateRequestSocket();
                client.Options.Linger   = TimeSpan.Zero;
                client.Options.Identity = Encoding.UTF8.GetBytes(requestId);
                client.Connect(address.Address);
                try
                {
                    byte[] data = Encoding.UTF8.GetBytes(msg);
                    client.Send(data);
                }
                catch (Exception)
                {
                    client.Disconnect(address.Address);
                    client.Dispose();
                    return(resp);
                }

                client.ReceiveReady += ClientOnReceiveReady;
                pollResult           = client.Poll(TimeSpan.FromMilliseconds(timeoutmsec));
                client.ReceiveReady -= ClientOnReceiveReady;
                client.Disconnect(address.Address);
                client.Dispose();
            }

            if (pollResult)
            {
                if (responseMsgs.ContainsKey(requestId))
                {
                    responseMsgs.TryRemove(requestId, out resp);
                }
            }

            return(resp);
        }
        public void Dispose()
        {
            if (_poller != null)
            {
                _poller.RemoveSocket(_worker);
                _poller.RemoveTimer(_heartbeatTimer);
                _poller = null;
            }

            if (_heartbeatTimer != null)
            {
                _heartbeatTimer.Elapsed -= heartbeatTimer_Elapsed;
                _heartbeatTimer          = null;
            }

            if (_scheduler != null)
            {
                //_scheduler.Dispose();
            }

            if (_worker != null)
            {
                _worker.ReceiveReady -= _worker_ReceiveReady;
                _worker.Disconnect("tcp://localhost:5556");
            }
        }
Exemple #3
0
        /// <summary>
        ///     Stop the server.
        /// </summary>
        public void StopServer()
        {
            if (!ServerRunning)
            {
                return;
            }

            _poller?.Stop();
            _poller?.Dispose();

            lock (_socketLock)
            {
                if (_socket != null)
                {
                    try
                    {
                        _socket.Disconnect(_connectionString);
                    }
                    finally
                    {
                        _socket.ReceiveReady -= SocketReceiveReady;
                        _socket.Close();
                        _socket = null;
                    }
                }
            }

            _poller = null;
        }
Exemple #4
0
        /// <summary>
        /// Stops the Client
        /// </summary>
        public void Stop()
        {
            isDone = true;
            listenerThread.Join();

            clientSocket.Disconnect(clientConnectionString);
            clientSocket.Close();
        }
Exemple #5
0
        protected override void StopConnection()
        {
            socket.Disconnect("tcp://localhost:5555");

            Debug.Log("Stopping Connection");

            socket.Dispose();
            NetMQConfig.Cleanup();
            isRunning = false;
        }
 private void InternalClose()
 {
     try
     {
         m_monitoringSocket.Disconnect(Endpoint);
     }
     catch (Exception)
     {}
     finally
     {
         IsRunning = false;
         m_isStoppedEvent.Set();
     }
 }
Exemple #7
0
        internal static void Stop(this NetMQSocket socket, string address, SocketType socketType)
        {
            switch (socketType)
            {
            case SocketType.Client:
                socket.Disconnect(address);
                break;

            case SocketType.Server:
                socket.Unbind(address);
                break;

            default:
                throw new ArgumentException(string.Format("Unknown SocketType {0}", socketType), "socketType");
            }
            socket.Close();
        }
        private static bool TryRequest(NetMQContext context, string endpoint, string requestString)
        {
            Console.WriteLine("Trying echo service at {0}", endpoint);
            NetMQSocket client = context.CreateRequestSocket();

            client.Options.Linger = TimeSpan.Zero;
            client.Connect(endpoint);
            client.Send(requestString);
            client.ReceiveReady += ClientOnReceiveReady;
            bool pollResult = client.Poll(TimeSpan.FromMilliseconds(REQUEST_TIMEOUT));

            client.ReceiveReady -= ClientOnReceiveReady;
            client.Disconnect(endpoint);
            client.Dispose();

            return(pollResult);
        }
Exemple #9
0
        /// <summary>
        ///     Stops the server.
        /// </summary>
        public void StopServer()
        {
            if (!ServerRunning)
            {
                return;
            }

            poller?.Stop();
            poller?.Dispose();

            lock (publisherSocketLock)
            {
                if (publisherSocket != null)
                {
                    try
                    {
                        publisherSocket.Disconnect(publisherConnectionString);
                    }
                    finally
                    {
                        publisherSocket.Close();
                        publisherSocket = null;
                    }
                }
            }

            lock (requestSocketLock)
            {
                if (requestSocket != null)
                {
                    try
                    {
                        requestSocket.Disconnect(requestConnectionString);
                    }
                    finally
                    {
                        requestSocket.ReceiveReady -= RequestSocketReceiveReady;
                        requestSocket.Close();
                        requestSocket = null;
                    }
                }
            }

            poller = null;
        }
Exemple #10
0
 private void TerminateClient(NetMQSocket client)
 {
     client.Disconnect(Address.OriginalString);
     client.Close();
 }
Exemple #11
0
 public void Disconnect(string address)
 {
     Socket.Disconnect(address);
     EndPoints.Remove(address);
 }
Exemple #12
0
 private static void TerminateClient(NetMQSocket client)
 {
     client.Disconnect(ServerEndpoint);
     client.Close();
 }
Exemple #13
0
 /// <summary>
 /// Disconnects from the validator
 /// </summary>
 public void Disconnect()
 {
     Socket.Disconnect(Address);
     Poller.StopAsync();
 }
Exemple #14
0
 public void Disconnect(Uri address)
 => socket.Disconnect(address.ToSocketAddress());
Exemple #15
0
        /// <summary>
        /// Disconnects from the server.
        ///  </summary>
        public void Disconnect(bool cancelStreams = true)
        {
            //start by canceling all active real time streams
            if (cancelStreams)
            {
                while (RealTimeDataStreams.Count > 0)
                {
                    CancelRealTimeData(RealTimeDataStreams.First().Instrument);
                }
            }

            _running = false;
            if (_poller != null && _poller.IsStarted)
            {
                _poller.Stop(true);
            }

            if (_heartBeatTimer != null)
            {
                _heartBeatTimer.Stop();
            }

            if (_dealerLoopThread != null && _dealerLoopThread.ThreadState == ThreadState.Running)
            {
                _dealerLoopThread.Join(10);
            }

            if (_reqSocket != null)
            {
                try
                {
                    _reqSocket.Disconnect(string.Format("tcp://{0}:{1}", _host, _realTimeRequestPort));
                }
                catch
                {
                    _reqSocket.Dispose();
                    _reqSocket = null;
                }
            }

            if (_subSocket != null)
            {
                try
                {
                    _subSocket.Disconnect(string.Format("tcp://{0}:{1}", _host, _realTimePublishPort));
                }
                catch
                {
                    _subSocket.Dispose();
                    _subSocket = null;
                }
            }

            if (_dealerSocket != null)
            {
                try
                {
                    _dealerSocket.Disconnect(string.Format("tcp://{0}:{1}", _host, _historicalDataPort));
                }
                catch
                {
                    _dealerSocket.Dispose();
                    _dealerSocket = null;
                }
            }
        }
Exemple #16
0
 private static void TerminateClient(NetMQSocket client)
 {
     client.Disconnect(ServerEndpoint);
     client.Close();
 }
 public void Execute(NetMQSocket socket)
 {
     socket.Disconnect(_address);
 }