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"); } }
/// <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; }
/// <summary> /// Stops the Client /// </summary> public void Stop() { isDone = true; listenerThread.Join(); clientSocket.Disconnect(clientConnectionString); clientSocket.Close(); }
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(); } }
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); }
/// <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; }
private void TerminateClient(NetMQSocket client) { client.Disconnect(Address.OriginalString); client.Close(); }
public void Disconnect(string address) { Socket.Disconnect(address); EndPoints.Remove(address); }
private static void TerminateClient(NetMQSocket client) { client.Disconnect(ServerEndpoint); client.Close(); }
/// <summary> /// Disconnects from the validator /// </summary> public void Disconnect() { Socket.Disconnect(Address); Poller.StopAsync(); }
public void Disconnect(Uri address) => socket.Disconnect(address.ToSocketAddress());
/// <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; } } }
public void Execute(NetMQSocket socket) { socket.Disconnect(_address); }