protected override void Run() { ForceDotNet.Force(); using var socket = new PushSocket(); socket.Connect("tcp://localhost:5556"); while (Running) { if (fromEventLoop.TryDequeue(out byte[] img)) { socket.TrySendFrame(img); } } }
private void PushMessage(Message message) { if (!_active) { throw new InvalidOperationException("ZeroMQ provider not started"); } var str = JsonConvert.SerializeObject(message); if (!_nodeSocket.TrySendFrame(TimeSpan.FromSeconds(3), str)) { throw new InvalidOperationException("Unable to send message"); } }
private void ExecuteComThreadTransmitControlMessages() { PushSocket pushSocket = null; try { pushSocket = new PushSocket(); pushSocket.Options.SendHighWatermark = 10; pushSocket.Connect(this.Config.GetConnectionStringCore4Transmit()); var watch = Stopwatch.StartNew(); while (!IsDisposed) { NetMq.Messages.BaseMessage baseMessage = null; if (Queue.TryDequeue(out baseMessage)) { var buffer = baseMessage.Buffer; if (pushSocket.TrySendFrame(TimeSpan.FromMilliseconds(100), buffer, false)) { this.Log($"{baseMessage.MessageType} was transfered to {pushSocket.Options.LastEndpoint}", 0); } else { this.Log("Error sending message"); } } else { Thread.Sleep(10); } if (watch.ElapsedMilliseconds > 999) { watch.Restart(); SendStateMessage(); } } } catch (Exception exp) { LastException = exp; } finally { pushSocket?.Dispose(); } }
public void Client(NodeDto connectingNode, DhtProtocolCommandDto protocolCommandDto) { var cleanAddress = connectingNode.IpAddress.Replace("127.0.0.1", "localhost"); var address = $"tcp://{cleanAddress}:{connectingNode.Port}"; // client = _clients.FirstOrDefault(socket => socket.Options.LastEndpoint.Equals(address)); // if (client == null) // { // client = new RequestSocket(); // _clients.Add(client); // } try { client.Connect(address); client.TrySendFrame(protocolCommandDto.ToString()); client?.Disconnect(address); // client.TryReceiveSignal(out bool signal); } catch (NetMQException e) { Log.Logger.Error(e, e.Message); Log.Debug(e.ErrorCode.ToString()); Log.Debug(e.StackTrace); Log.Debug(e.Message); Console.WriteLine(e.ErrorCode); Console.WriteLine(e.Message); Console.WriteLine(e.InnerException); Console.WriteLine(address); } catch (Exception exception) { Log.Logger.Error(exception, exception.Message); Log.Debug(exception.Message); } finally { // _clients.Remove(client); // client?.Disconnect(address); // client?.Dispose(); } }
public Task EnqueueNotificationAsync(Tweet tweet) { var serializedObject = JsonConvert.SerializeObject(tweet); return(Task.Factory.StartNew(() => _client.TrySendFrame(TimeSpan.FromSeconds(1), serializedObject), CancellationToken.None, TaskCreationOptions.None, _scheduler)); }