public static void Main(string[] args) { using (var context = new Context(1)) { // Connect to task ventilator and weather server using (Socket receiver = context.Socket(SocketType.PULL), subscriber = context.Socket(SocketType.SUB)) { receiver.Connect("tcp://localhost:5557"); subscriber.Connect("tcp://localhost:5556"); subscriber.Subscribe("10001 ", Encoding.Unicode); var items = new PollItem[2]; items[0] = receiver.CreatePollItem(IOMultiPlex.POLLIN); items[0].PollInHandler += ReceiverPollInHandler; items[1] = subscriber.CreatePollItem(IOMultiPlex.POLLIN); items[1].PollInHandler += SubscriberPollInHandler; // Process messages from both sockets while (true) { context.Poll(items, -1); } } } }
static void Main(string[] args) { using (var context = new Context(1)) using (var receiver = context.Socket(SocketType.PULL)) { receiver.Connect("tcp://localhost:5557"); using (var sender = context.Socket(SocketType.PUSH)) { sender.Connect("tcp://localhost:5558"); using (var controller = context.Socket(SocketType.SUB)) { controller.Connect("tcp://localhost:5559"); controller.Subscribe(string.Empty, Encoding.Unicode); bool run = true; PollItem[] items = new PollItem[2]; items[0] = receiver.CreatePollItem(IOMultiPlex.POLLIN); items[0].PollInHandler += (socket, revents) => ReceiverPollInHandler(socket, sender); items[1] = controller.CreatePollItem(IOMultiPlex.POLLIN); items[1].PollInHandler += delegate { run = false; }; // Process tasks as long as the controller does not signal the end. while (run) { context.Poll(items); } } } } }
public void Run() { using (var context = new Context(1)) { using (var pub = context.Socket(SocketType.PUB)) using (var control = context.Socket(SocketType.SUB)) { pub.Bind("inproc://workers"); var step2 = new Thread(() => Worker(context)); step2.Start(); Thread.Sleep(100); control.Connect("inproc://control"); control.Subscribe("", Encoding.Unicode); var count = 0; var message = string.Empty; var controlItems = new PollItem[2]; controlItems[0] = control.CreatePollItem(IOMultiPlex.POLLIN); controlItems[0].PollInHandler += (x, y) => { message = x.Recv(Encoding.Unicode); Console.WriteLine("A message: {0}", message); }; controlItems[1] = pub.CreatePollItem(IOMultiPlex.POLLOUT); controlItems[1].PollOutHandler += (z, y) => { Console.WriteLine(string.Format("About to send {0}", count)); z.Send(count++.ToString(), Encoding.Unicode); }; //Console.WriteLine("Recieved the {0} signal",control.Recv(Encoding.Unicode)); while (string.IsNullOrEmpty(message) || !message.Equals("Stop")) { context.Poll(controlItems, -1); Thread.Sleep(500); } } } }
static void Main(string[] args) { Context contexto = new Context(); router = contexto.Socket(SocketType.ROUTER); dealer = contexto.Socket(SocketType.DEALER); router.Identity = Guid.NewGuid().ToByteArray(); router.Bind("tcp://*:5589"); dealer.Bind("tcp://*:5590"); items[0] = router.CreatePollItem(IOMultiPlex.POLLIN); items[1] = dealer.CreatePollItem(IOMultiPlex.POLLIN); items[0].PollInHandler += new PollHandler(RecepcionRouter); items[1].PollInHandler+= new PollHandler(RecepcionDealer); //hiloPoller = new Thread(IniciarRecepcion); //hiloPoller.Start(new ParametrosInicio { context = contexto, pollitems = items }); while (true) { contexto.Poll(items, -1); } }
public static void Main(string[] args) { using (var context = new Context(1)) { using (Socket frontend = context.Socket(SocketType.ROUTER), backend = context.Socket(SocketType.DEALER)) { frontend.Bind("tcp://*:5559"); backend.Bind("tcp://*:5560"); var pollItems = new PollItem[2]; pollItems[0] = frontend.CreatePollItem(IOMultiPlex.POLLIN); pollItems[0].PollInHandler += (socket, revents) => FrontendPollInHandler(socket, backend); pollItems[1] = backend.CreatePollItem(IOMultiPlex.POLLIN); pollItems[1].PollInHandler += (socket, revents) => BackendPollInHandler(socket, frontend); while (true) { context.Poll(pollItems, -1); } } } }
static void Main(string[] args) { Context contexto = new Context(); enviar= contexto.Socket(SocketType.REQ); recibir = contexto.Socket(SocketType.REP); Console.WriteLine("Cual es el nombre del cliente"); nombre=Console.ReadLine(); recibir.Identity = Encoding.Unicode.GetBytes(nombre); enviar.Connect("tcp://127.0.0.1:5589"); recibir.Connect("tcp://127.0.0.1:5590"); enviar.Send(Encoding.Unicode.GetBytes(nombre)); servidor=enviar.Recv(Encoding.Unicode); Console.WriteLine("Conectado"); items[0] = recibir.CreatePollItem(IOMultiPlex.POLLIN); items[0].PollInHandler += new PollHandler(RecibirMensaje); while (true) { contexto.Poll(items, -1); } Console.ReadKey(); enviar.Dispose(); }