//static void SetSocketOpt(NetMQSocket socket) //{ // socket.Options.TcpKeepalive = true; // socket.Options.ReconnectIntervalMax = TimeSpan.FromMilliseconds(30000); // socket.Options.Linger = TimeSpan.FromMilliseconds(0); // //socket.KeepAlive = true; // //socket.ReconnectIntervalMax = TimeSpan.FromMilliseconds(30000); // //socket.Linger = TimeSpan.FromMilliseconds(0); //} static public Socket_NanoMsg Create(SocketType socketType) { NanomsgSocketBase socket; switch (socketType) { case SocketType.Pub: socket = new PublishSocket(); return(new Socket_NanoMsg(socket)); case SocketType.Pull: socket = new PullSocket(); return(new Socket_NanoMsg(socket)); case SocketType.Push: socket = new PushSocket(); return(new Socket_NanoMsg(socket)); case SocketType.Sub: socket = new SubscribeSocket(); return(new Socket_NanoMsg(socket)); default: throw new Exception("Non support SocketType."); } }
public LzoNanoData(string DataAddress) { DATAAddress = DataAddress; subscriber = new SubscribeSocket(); subscriber.Options.ReconnectInterval = new TimeSpan(0, 0, 1); subscriber.Connect(DataAddress); Console.WriteLine("NANOMQ UDP_Reciever Start DataAddress: " + DataAddress); }
public void Setup(String id) { this.id = id; this.interaction = new RequestSocket(); this.world = new SubscribeSocket(); this.req_register = "REG " + id; this.req_access = "ACCESS " + id; this.req_end = "END " + id; this.acknowledged = id + "-ACK"; this.denied = id + "-DENIED"; this.connected = false; this.listenThread = null; }
public Subscriber(string[] connections, string subscription = "") { _socket = new SubscribeSocket(); foreach (string connection in connections) { _socket.Connect(connection); } _socket.Subscribe(subscription); Thread.Sleep(100); // time to connect _db = new DBManager(); }
public PubSubSpecs() { ClientFiber = PoolFiber.StartNew(); Context1 = NetMQContext.Create(); Send = new SendSocket <string>(Context1, "tcp://localhost:6001", s => Encoding.Unicode.GetBytes(s)); Context2 = NetMQContext.Create(); RcvdSignal = new ManualResetEvent(false); Subscriber = new SubscribeSocket <string>(Context2, "tcp://localhost:6001", x => Encoding.Unicode.GetString(x), Channel); Subscriber.SubscribeAll(); }
public PubSubSpecs() { ClientFiber = PoolFiber.StartNew(); Context1 = NetMQContext.Create(); Send = new SendSocket<string>(Context1, "tcp://localhost:6001", s => Encoding.Unicode.GetBytes(s)); Context2 = NetMQContext.Create(); RcvdSignal = new ManualResetEvent(false); Subscriber = new SubscribeSocket<string>(Context2, "tcp://localhost:6001", x => Encoding.Unicode.GetString(x), Channel); Subscriber.SubscribeAll(); }
public static void Execute(string[] args) { string[] values = args; if (values.Length != 3) { throw new ArgumentException("Invalid number parameters."); } switch (values[1].Trim().ToLower()) { case "publisher": using (var s = new PublishSocket()) { s.Bind(values[2]); int i = 0; while (true) { byte[] b = Encoding.ASCII.GetBytes("Publish Counter is " + ++i); s.Send(b); Console.Write("."); Thread.Sleep(2000); } } break; case "subscriber": using (var s = new SubscribeSocket()) { //Needs to match the first portion of the message being received. s.Subscribe("Publish Counter"); s.Connect(values[2]); while (true) { byte[] b = s.Receive(); if (b != null) { Console.WriteLine("Received: " + Encoding.ASCII.GetString(b)); } else { Console.WriteLine("x"); } } } break; } }
public void _socketfun() { _requestSocket = new RequestSocket(); _requestSocket.Connect("tcp://" + Global.Instance.NNFConIp + ":" + Global.Instance.NNFConPUBPort); _subscribeSocket = new SubscribeSocket(); _subscribeSocket.Connect("tcp://" + Global.Instance.NNFConIp + ":" + Global.Instance.NNFConSUBPort); long client_Autoid = Global.Instance.ClientId - 100; _subscribeSocket.Subscribe(BitConverter.GetBytes((short)MessageType.LOGIN).Concat(BitConverter.GetBytes(Global.Instance.ClientId)).ToArray()); dllevent += new dll(checkCase); _CTS = new CancellationTokenSource(); }
public static void Execute() { Console.WriteLine("Executing pubsub test "); int receiveCount = 0; var clientThread = new Thread( () => { var subscriber = new SubscribeSocket(); subscriber.Connect(InprocAddress); subscriber.Subscribe("TestMessage"); byte[] streamOutput = new byte[BufferSize]; while (true) { var sw = Stopwatch.StartNew(); for (int i = 0; i < Iter; i++) { int read = 0; streamOutput = subscriber.Receive(); read = streamOutput.Length; //using (var stream = subscriber.ReceiveStream()) // while (stream.Length != stream.Position) // { // read += stream.Read(streamOutput, 0, streamOutput.Length); // var message = Encoding.ASCII.GetString(streamOutput, 0, read); // Trace.Assert(message.StartsWith("TestMessage")); // // break; // } ++receiveCount; } sw.Stop(); var secondsPerSend = sw.Elapsed.TotalSeconds / (double)Iter; Console.WriteLine("Time {0} us, {1} per second, {2} mb/s ", (int)(secondsPerSend * 1000d * 1000d), (int)(1d / secondsPerSend), (int)(DataSize * 2d / (1024d * 1024d * secondsPerSend))); } }); clientThread.Start(); { var publisher = new PublishSocket(); publisher.Bind(InprocAddress); Thread.Sleep(100); var sw = Stopwatch.StartNew(); int sendCount = 0; var text = "TestMessage" + new string('q', 10); var data = Encoding.ASCII.GetBytes(text); while (sw.Elapsed.TotalSeconds < 10) { publisher.Send(data); ++sendCount; } Thread.Sleep(100); clientThread.Abort(); Console.WriteLine("Send count {0} receive count {1}", sendCount, receiveCount); publisher.Dispose(); } }