static void Main(string[] args) { Console.WriteLine("NetMq hello wolrd client have started:"); using (var client = new RequestSocket()) { client.Connect("tcp://localhost:" + portToConnectTo); Console.WriteLine("Sending message, using 'A' as the first frame"); client.SendMoreFrame("A").SendFrame("I am saying"); var message = client.ReceiveFrameString(); Console.WriteLine("Received {0}", message); Console.WriteLine("Sending message, using 'B' as the first frame"); client.SendMoreFrame("B").SendFrame(", world!"); message = client.ReceiveFrameString(); Console.WriteLine("Received {0}", message); client.SendMoreFrame("C").SendFrame(", world!"); message = client.ReceiveFrameString(); Console.WriteLine("Received {0}", message); //waiting so the tester can see the console Console.ReadKey(); } }
private void Update() { for (int i = 0; i < images.Count; i++) { Destroy(images[i]); } images.Clear(); client.SendFrame("num_keypoints"); int num_keypoints = Int32.Parse(client.ReceiveFrameString()); for (int i = 0; i < num_keypoints; i++) { client.SendFrame("Loc_x"); string Loc_x = client.ReceiveFrameString(); client.SendFrame("Loc_y"); string Loc_y = client.ReceiveFrameString(); Debug.Log("Loc_y: " + Loc_y + " Loc_x: " + Loc_x); int Pos_x = Int32.Parse(Loc_x); int Pos_y = Int32.Parse(Loc_y); GameObject temp = Instantiate(img); temp.transform.position = new Vector2(Pos_x, Pos_y); temp.transform.SetParent(canvas.transform); images.Add(temp); } }
static void Main(string[] args) { String outgoingMessage; using (var VESendSocket = new RequestSocket(">tcp://206.189.9.238:5560")) { ThreadStart threadRef = new ThreadStart(ChatReceiveThread); Thread thread = new Thread(threadRef); thread.Start(); Console.WriteLine("Connecting to chat"); VESendSocket.SendFrame(""); String answer = VESendSocket.ReceiveFrameString(); Console.WriteLine(answer); while (true) { outgoingMessage = Console.ReadLine(); VESendSocket.SendFrame(outgoingMessage); answer = VESendSocket.ReceiveFrameString(); } } }
void InquiryInformation() { var id = ""; var name = ""; using (var requester = new RequestSocket($"tcp://{EndPoint.ToString()}")) { id = requester.ReceiveFrameString(); name = requester.ReceiveFrameString(); } ID = Guid.Parse(id); Name = name; }
public IActionResult CreateAction([FromBody] ServerAction action) { var name = GetGivenName(); var permissions = _permissionsContext.Permissions.Where(x => x.Name == name); if (!permissions.Any(x => x.Target == action.Target)) { return(Unauthorized()); } Console.WriteLine("Opening a request socket to " + _zmqUrl); using (var requestSocket = new RequestSocket(">" + _zmqUrl)) { switch (action.Type) { case ActionType.Start: requestSocket.SendFrame(JsonConvert.SerializeObject(new Message <IStartServerCommand>(MessageType.Command, new StartServerCommand(action.Target)), new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() })); return(Ok(requestSocket.ReceiveFrameString())); break; case ActionType.Stop: requestSocket.SendFrame(JsonConvert.SerializeObject(new Message <IStopServerCommand>(MessageType.Command, new StopServerCommand(action.Target)), new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() })); return(Ok(requestSocket.ReceiveFrameString())); break; case ActionType.Restart: requestSocket.SendFrame(JsonConvert.SerializeObject(new Message <IRestartServerCommand>(MessageType.Command, new RestartServerCommand(action.Target)), new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() })); return(Ok(requestSocket.ReceiveFrameString())); break; case ActionType.None: default: throw new ArgumentOutOfRangeException(); } } return(Ok()); }
public Pupil(string IP = "127.0.0.1", string PORT = "50020") { NetMQConfig.ContextCreate(true); requestSocket = new RequestSocket(">tcp://" + IP + ":" + PORT); float t = Time.time; requestSocket.SendFrame("t"); string response = requestSocket.ReceiveFrameString(); requestSocket.SendFrame("T 0.0"); response = requestSocket.ReceiveFrameString(); SetTimestamp(Time.time); }
private void receiveData() { try { if (pickDate.Checked) { using (var requestSocket = new RequestSocket(">tcp://localhost:5555")) { requestSocket.SendFrame("date"); windowLogs.Items.Add(DateTime.Now.ToString() + ". Wysłano prośbę o datę"); DateTime dateTime = DateTime.Parse(requestSocket.ReceiveFrameString()); windowLogs.Items.Add(DateTime.Now.ToString() + ". Odebraną datę: " + dateTime.ToString("dddd, dd MMMM yyyy")); } } if (pickTime.Checked) { using (var requestSocket = new RequestSocket(">tcp://localhost:5555")) { requestSocket.SendFrame("time"); windowLogs.Items.Add(DateTime.Now.ToString() + ". Wysłano prośbę o czas"); TimeSpan timeSpan = TimeSpan.Parse(requestSocket.ReceiveFrameString()); windowLogs.Items.Add(DateTime.Now.ToString() + ". Odebraną czas: " + timeSpan.ToString()); } } } catch (SocketException se) { MessageBox.Show(se.Message); } }
static void Main(string[] args) { using (var client = new RequestSocket()) { client.Connect("tcp://localhost:5555"); for (int i = 0; i < 10; i++) { var calculation = new Calculation() { Operand1 = i, Operand2 = 2 * i, Operator = "+" }; var calculationMessage = JsonSerializer.Serialize(calculation); Console.WriteLine("Sending {0}", calculationMessage); client.SendFrame(calculationMessage); var message = client.ReceiveFrameString(); Console.WriteLine("Received {0}", message); var result = JsonSerializer.Deserialize <CalculationResult>(message); Console.WriteLine(result.Result); } } }
public string recieve() { string message = client.ReceiveFrameString(); Debug.Log($"C: Frame recieved...{message}"); return(message); }
public void ResponsePoll() { using (var rep = new ResponseSocket()) using (var req = new RequestSocket()) using (var poller = new Poller(rep) { PollTimeout = TestPollTimeoutMillis }) { int port = rep.BindRandomPort("tcp://127.0.0.1"); req.Connect("tcp://127.0.0.1:" + port); rep.ReceiveReady += (s, e) => { bool more; Assert.AreEqual("Hello", e.Socket.ReceiveFrameString(out more)); Assert.False(more); e.Socket.SendFrame("World"); }; poller.PollTillCancelledNonBlocking(); req.SendFrame("Hello"); bool more2; Assert.AreEqual("World", req.ReceiveFrameString(out more2)); Assert.IsFalse(more2); poller.CancelAndJoin(); } }
public async Task RunAsync(string[] args, AppInfo appInfo, Func <Task> whenFirstInstance) { if (IsApplicationFirstInstance(appInfo.Name)) { // args[0] is always the path to the application // update system registry AuthConfig.WinDesktopUseBrowserAuth(appInfo, args[0]); await whenFirstInstance(); } else { // We are not the first instance, send the argument received from browser auth, to the currently running instance if (args.Length >= 2) { using (var client = new RequestSocket("tcp://localhost:5556")) { // very important to wait for the ack, otherwise we'll be running through this block too fast, // and the first sent message will actually not be picked up by recipient, and auth process will never complete. client.SendFrame(args[1]); var ack = client.ReceiveFrameString(); Console.WriteLine(ack); Console.WriteLine($"Switch back to your application.."); Thread.Sleep(1000); // allow a short moment to percieve the above writelines } } // Close app return; } }
static async Task Main(string[] args) { using (var responseSocket = new ResponseSocket("tcp://*:5555")) using (var requestSocket = new RequestSocket("tcp://localhost:5555")) { Console.WriteLine("requestSocket : Sending 'Hello'"); requestSocket.SendFrame("Hello"); var message = responseSocket.ReceiveFrameString(); Console.WriteLine("responseSocket : Server Received '{0}'", message); Console.WriteLine("responseSocket Sending 'World'"); responseSocket.SendFrame("World"); message = requestSocket.ReceiveFrameString(); Console.WriteLine("requestSocket : Received '{0}'", message); Console.ReadLine(); } Console.WriteLine("ZeroMQ intra-app communications demo"); Console.WriteLine("Use CTRL+C shortcut to cancel at any time"); var echoServerTask = EchoServer(); var streamTask = StreamServer(); var streamToConsoleTask = PushStreamToConsole(); var consoleToEchoTask = RelayConsoleToEchoServer(); await Task.WhenAll(echoServerTask, streamTask, streamToConsoleTask, consoleToEchoTask); }
public static void Main(string[] args) { using (var server = new ResponseSocket("@tcp://localhost:5556")) using (var client = new RequestSocket(">tcp://localhost:5556")) { Console.WriteLine("Unesite nick"); var nick = Console.ReadLine(); while (true) { Console.WriteLine("Unesite poruku"); var messageContent = Console.ReadLine(); Message message = new Message(nick, messageContent); client.SendFrame(message.ToString()); string m1 = server.ReceiveFrameString(); string[] nickname = m1.Split(','); Console.WriteLine("From Client: {0},message: {1}", nickname[0], nickname[1]); server.SendFrame("Hi " + nickname[0]); string m2 = client.ReceiveFrameString(); Console.WriteLine("From Server: {0}", m2); } } }
static void Main(string[] args) { var rand = new Random(); while (true) { // specify one ephemeral port int port = rand.Next(49152, 65535); string address = $"tcp://*****:*****@{address}")) using (var client = new RequestSocket($">{address}")) { while (true) { client.SendFrame("Hello"); Console.WriteLine($"From client: {server.ReceiveFrameString()}"); server.SendFrame("Hi Back"); Console.WriteLine($"From server: {client.ReceiveFrameString()}"); Thread.Sleep(1000); } } } catch (AddressAlreadyInUseException) { Console.WriteLine($"This address is in use. Let's pick onther one."); } } }
static void Main(string[] args) { Console.WriteLine("Press any key to start!"); Console.Read(); NetMQPoller Poller2 = new NetMQPoller(); NetMQQueue <int> Queue = new NetMQQueue <int>(); for (var i = 0; i < 10; i++) { Task.Factory.StartNew((o) => { using (var req = new RequestSocket(">tcp://127.0.0.1:5001")) { if (req.TrySendFrame(TimeSpan.FromSeconds(1), $"task:{o}")) { var msg = req.ReceiveFrameString(); Console.WriteLine(msg); } else { Console.WriteLine($"task:{i} timeout!"); } } }, i); } Console.WriteLine("Press any key to stop!"); Console.Read(); Console.Read(); }
public void ResponsePoll() { using (var rep = new ResponseSocket()) using (var req = new RequestSocket()) using (var poller = new NetMQPoller { rep }) { int port = rep.BindRandomPort("tcp://127.0.0.1"); req.Connect("tcp://127.0.0.1:" + port); rep.ReceiveReady += (s, e) => { bool more; Assert.AreEqual("Hello", e.Socket.ReceiveFrameString(out more)); Assert.False(more); e.Socket.SendFrame("World"); }; poller.RunAsync(); req.SendFrame("Hello"); bool more2; Assert.AreEqual("World", req.ReceiveFrameString(out more2)); Assert.IsFalse(more2); poller.Stop(); } }
public void SendAndReceive() { using (var front = new RouterSocket()) using (var back = new DealerSocket()) { front.Bind("inproc://frontend"); back.Bind("inproc://backend"); var proxy = new Proxy(front, back); Task.Factory.StartNew(proxy.Start); using (var client = new RequestSocket()) using (var server = new ResponseSocket()) { client.Connect("inproc://frontend"); server.Connect("inproc://backend"); client.SendFrame("hello"); Assert.AreEqual("hello", server.ReceiveFrameString()); server.SendFrame("reply"); Assert.AreEqual("reply", client.ReceiveFrameString()); } proxy.Stop(); } }
static void Main(string[] args) { uint basePort = 15000; var hostname = Environment.GetEnvironmentVariable("CAMERASERVER_ZMQ_SERVERHOSTNAME") ?? "localhost"; UInt32.TryParse(Environment.GetEnvironmentVariable("CAMERASERVER_ZMQ_SERVERBASEPORT") ?? "15000", out basePort); using (var server = new CameraServer(hostname, basePort)) { Console.WriteLine("Starting"); Console.CancelKeyPress += (sender, e) => { e.Cancel = true; Console.WriteLine("Cancel Key Press"); using (var testClientSocket = new RequestSocket($"tcp://localhost:{basePort}")) { testClientSocket.SendFrame(JsonConvert.SerializeObject(new Command() { Name = Command.SHUTDOWN_COMMAND })); var response = testClientSocket.ReceiveFrameString(); } Console.WriteLine("Shutdown ack"); }; server.Start(); Console.WriteLine("Running"); server.Task.Wait(); Console.WriteLine("Shutdown"); } }
public void MonitorDisposeProperlyWhenDisposedAfterMonitoredTcpSocket() { // The bug: // Given we monitor a netmq tcp socket // Given we disposed of the monitored socket first // When we dispose of the monitor // Then our monitor is Faulted with a EndpointNotFoundException // And monitor can't be stopped or disposed using (var res = new ResponseSocket()) { NetMQMonitor monitor; using (var req = new RequestSocket()) { monitor = new NetMQMonitor(req, "inproc://#monitor", SocketEvents.All); Task.Factory.StartNew(monitor.Start); // Bug only occurs when monitoring a tcp socket var port = res.BindRandomPort("tcp://127.0.0.1"); req.Connect("tcp://127.0.0.1:" + port); req.SendFrame("question"); Assert.That(res.ReceiveFrameString(), Is.EqualTo("question")); res.SendFrame("response"); Assert.That(req.ReceiveFrameString(), Is.EqualTo("response")); } Thread.Sleep(100); // Monitor.Dispose should complete var completed = Task.Factory.StartNew(() => monitor.Dispose()).Wait(1000); Assert.That(completed, Is.True); } // NOTE If this test fails, it will hang because context.Dispose will block }
public void StartAndStopStateValidation() { using (var front = new RouterSocket()) using (var back = new DealerSocket()) { front.Bind("inproc://frontend"); back.Bind("inproc://backend"); var proxy = new Proxy(front, back); Task.Factory.StartNew(proxy.Start); // Send a message through to ensure the proxy has started using (var client = new RequestSocket()) using (var server = new ResponseSocket()) { client.Connect("inproc://frontend"); server.Connect("inproc://backend"); client.SendFrame("hello"); Assert.AreEqual("hello", server.ReceiveFrameString()); server.SendFrame("reply"); Assert.AreEqual("reply", client.ReceiveFrameString()); } Assert.Throws <InvalidOperationException>(proxy.Start); Assert.Throws <InvalidOperationException>(proxy.Start); Assert.Throws <InvalidOperationException>(proxy.Start); proxy.Stop(); // blocks until stopped Assert.Throws <InvalidOperationException>(proxy.Stop); } }
static void Main(string[] args) { using (var client = new RequestSocket()) { client.Connect("tcp://localhost:5555"); Console.WriteLine("Client connected to tcp://127.0.0.1:5555"); Console.WriteLine("Press <Enter> to send request. Press <Esc> to quit."); ConsoleKeyInfo cki; while (true) { cki = Console.ReadKey(); if (cki.Key == ConsoleKey.Enter) { client.SendFrame("Hello from client!"); var message = client.ReceiveFrameString(); Console.WriteLine("Recieved {0} from Server.", message); } if (cki.Key == ConsoleKey.Escape) { break; } } } }
public static void Main(string[] args) { using (var requestSocket = new RequestSocket("tcp://localhost:5555")) { Console.WriteLine("requestSocket : Sending 'Hello'"); requestSocket.SendFrame("Hello"); var message = requestSocket.ReceiveFrameString(); Account account = JsonConvert.DeserializeObject <Account>(message); Console.WriteLine("requestSocket : Received '{0}'", account); Console.WriteLine(" Branch checkin "); Console.ReadLine(); Console.WriteLine(" Testing of the rebasing in the "); Console.WriteLine(" Testing of the rebasing in the "); Console.WriteLine(" Testing of the rebasing in the -2nd attempt"); Console.WriteLine(" Testing of the rebasing in the -3rd attempt"); Console.WriteLine(" Rebasing branch - Testing of the rebasing in the -4rd attempt"); Console.WriteLine(" Testing of the rebasing in the -4th attempt"); Console.WriteLine(" Rebasing branch - Testing of the rebasing in the -4rd attempt"); Console.WriteLine(" Testing of the rebasing in the -4th attempt"); } }
public void HelloWorld() { var timer = new Timer(60000); timer.Start(); timer.Elapsed += (sender, args) => { this.Cancel = true; timer.Stop(); }; // Create const string endpoint = "tcp://*:4505"; using (var request = new RequestSocket()) { request.Bind(endpoint); Thread.Sleep(2000); while (true) { request.SendFrame("Requester says hello"); var reply = request.ReceiveFrameString(); Debug.WriteLine("Gets reply " + reply); } } }
public void RunRequestSocket() { using (var client = new RequestSocket()) { client.Connect("tcp://localhost:5555"); client.SendFrame("Send Pose"); var msg = client.ReceiveFrameString(); //Console.WriteLine("From Server: {0}", msg); buffer = msg.Split(','); tx = (float)Convert.ToDouble(buffer[0]); ty = (float)Convert.ToDouble(buffer[1]); tz = (float)Convert.ToDouble(buffer[2]); roll = (float)Convert.ToDouble(buffer[3]); pitch = (float)Convert.ToDouble(buffer[4]); yaw = (float)Convert.ToDouble(buffer[5]); Console.WriteLine("tx: " + tx); Console.WriteLine("ty: " + ty); Console.WriteLine("tz: " + tz); Console.WriteLine("roll: " + roll); Console.WriteLine("pitch: " + pitch); Console.WriteLine("yaw: " + yaw); } }
protected override void Run() { AsyncIO.ForceDotNet.Force(); // this line is needed to prevent unity freeze after one use, not sure why yet using (SUB = new SubscriberSocket()) using (PUB = new PublisherSocket()) using (REQ = new RequestSocket()) { SUB.Connect("tcp://localhost:5555"); SUB.Subscribe(""); PUB.Connect("tcp://localhost:5556"); REQ.Connect("tcp://localhost:5557"); Debug.Log("Connected: Receiving Messages"); while (Running) { /*Receive continuos Slicer data*/ string msg = SUB.ReceiveFrameString(); /*Send continuos Unity data*/ var bytes = new byte[dataPackage.t.Length * 4]; System.Buffer.BlockCopy(dataPackage.t, 0, bytes, 0, bytes.Length); PUB.SendFrame(bytes); /*Request volume data once*/ if (reqestData) { REQ.SendFrame("volume"); string msg2 = REQ.ReceiveFrameString(); Debug.Log(msg2); byte[] file = System.IO.File.ReadAllBytes(msg2); Debug.Log(file.Length); int d1 = System.BitConverter.ToInt32(file, 0); int d2 = System.BitConverter.ToInt32(file, 4); int d3 = System.BitConverter.ToInt32(file, 8); float[] volume = new float[d1 * d2 * d3]; System.Buffer.BlockCopy(file, 12, volume, 0, volume.Length * sizeof(float)); string s = d1 + " " + d2 + " " + d3 + " : "; //for (int i = 0; i < volume.Length; ++i) s += volume[i] + " "; Debug.Log(s); reqestData = false; } /*60fps*/ System.Threading.Thread.Sleep(16); } SUB.Close(); PUB.Close(); REQ.Close(); } NetMQConfig.Cleanup(); }
private void pobierzStalaCzasowa() { using (RequestSocket rs = new RequestSocket(">tcp://" + AdresIp.IP + ":5555")) { rs.SendFrame("CZAS"); stalaTekst.Text = rs.ReceiveFrameString() + " ms"; } }
private static async Task WaitForResponse(RequestSocket client) { await Task.Run(() => { string m2 = client.ReceiveFrameString(); Console.WriteLine("CLIENT: From Server: {0}", m2); }); }
private void pobierzStalaCzasowa_Click(object sender, EventArgs e) { using (RequestSocket rs = new RequestSocket(">tcp://" + poleNaIp.Text + ":5555")) { rs.SendFrame("CZAS"); interwal.Text = rs.ReceiveFrameString(); } }
static void Main(string[] args) { using (var server = new RequestSocket(">tcp://206.189.9.238:5555")) { String serverMessage; using (var process1 = new Process()) { process1.StartInfo.FileName = @"..\..\..\VEChat\bin\Debug\VEChat.exe"; process1.Start(); } Console.WriteLine("Visual educator client."); //Connecting to server server.SendFrame(""); //Receiving connection confirmation serverMessage = server.ReceiveFrameString(); Console.WriteLine(serverMessage); server.SendFrame(""); //Confirmation both parties are connected serverMessage = server.ReceiveFrameString(); Console.WriteLine(serverMessage); Console.WriteLine("Press enter to initiate the examination"); Console.ReadLine(); server.SendFrame(""); serverMessage = server.ReceiveFrameString(); Console.WriteLine(serverMessage); server.SendFrame(""); serverMessage = server.ReceiveFrameString(); Console.WriteLine(serverMessage); Console.ReadLine(); } }
static void Main(string[] args) { using (var client = new RequestSocket(">tcp://localhost:5555")) { client.SendFrame("I'm a Message."); string s = client.ReceiveFrameString(); Console.WriteLine("Echo: {0}", s); } }
private static void Main() { Console.Title = "NetMQ HelloWorld"; using (var server = new ResponseSocket("@tcp://localhost:5556")) using (var client = new RequestSocket("tcp://localhost:5556")) { client.SendFrame("Hello"); Console.WriteLine("From Client: {0}", server.ReceiveFrameString()); server.SendFrame("Hi Back"); Console.WriteLine("From Server: {0}", client.ReceiveFrameString()); Console.WriteLine(); Console.Write("Press any key to exit..."); Console.ReadKey(); } }
private static void ClientRoutine(object clientId) { try { using (var req = new RequestSocket()) { req.Connect("tcp://localhost:5555"); byte[] message = Encoding.Unicode.GetBytes(string.Format("{0} Hello", clientId)); Console.WriteLine("Client {0} sent \"{0} Hello\"", clientId); req.SendFrame(message, message.Length); var response = req.ReceiveFrameString(Encoding.Unicode); Console.WriteLine("Client {0} received \"{1}\"", clientId, response); } } catch (Exception ex) { Console.WriteLine("Exception on ClientRoutine: {0}", ex.Message); } }
private static void WorkerTask(object portNumber) { var random = new Random(DateTime.Now.Millisecond); using (var worker = new RequestSocket()) { // We use a string identity for ease here string id = ZHelpers.SetID(worker, Encoding.Unicode); string cnn = $"tcp://localhost:{portNumber}"; worker.Connect(cnn); Console.WriteLine("[W] ID {0} connect to {1}", id, cnn); int total = 0; bool end = false; while (!end) { // Tell the router we're ready for work worker.SendFrame("Ready"); //Console.WriteLine("[W] Message sent: {0}", msg); // Get workload from router, until finished string workload = worker.ReceiveFrameString(); //Console.WriteLine("[W] Workload received: {0}", workload); if (workload == "END") { end = true; } else { total++; Thread.Sleep(random.Next(1, 1000)); // Simulate 'work' } } Console.WriteLine("ID ({0}) processed: {1} tasks", Encoding.Unicode.GetString(worker.Options.Identity), total); } }