private CreateRequestSocket ( ) : RequestSocket | ||
return | RequestSocket |
internal NmqMessageSender(Uri serviceUri) { context = NetMQContext.Create(); socket = context.CreateRequestSocket(); var address = string.Format("tcp://{0}:{1}", serviceUri.Host, serviceUri.Port); socket.Connect(address); }
private static RequestSocket CreateServerSocket(NetMQContext context) { Console.WriteLine("C: Connecting to server..."); var client = context.CreateRequestSocket(); client.Connect(SERVER_ENDPOINT); client.Options.Linger = TimeSpan.Zero; client.ReceiveReady += ClientOnReceiveReady; return client; }
/// <summary> /// just to create the REQ socket /// </summary> /// <param name="context">current NetMQContext</param> /// <param name="id">the name for the client</param> /// <returns>the connected REQ socket</returns> private static RequestSocket CreateSocket(NetMQContext context, string id) { var client = context.CreateRequestSocket(); client.Options.Identity = Encoding.UTF8.GetBytes(id); client.Options.Linger = TimeSpan.Zero; // set the event to be called upon arrival of a message client.ReceiveReady += OnClientReceiveReady; client.Connect(Commons.QueueFrontend); return client; }
private static RequestSocket CreateServerSocket(NetMQContext context) { Console.WriteLine("C: Connecting to server..."); var client = context.CreateRequestSocket(); client.Options.Linger = TimeSpan.Zero; Guid guid = Guid.NewGuid(); client.Options.Identity = Encoding.Unicode.GetBytes(guid.ToString()); client.Connect(SERVER_ENDPOINT); client.ReceiveReady += ClientOnReceiveReady; return client; }
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> /// Client does the following: /// * Creates a Request socket /// * Sends a "Hello" message /// * Waits for a "World" reply /// </summary> /// <param name="context"></param> private void Client(NetMQContext context) { // creating the request socket inside using to automatically dispose the socket using (var request = context.CreateRequestSocket()) { // connecting to the response socket request.Connect("tcp://localhost:5555"); // sending a request message, SendFrame has multiple overload you can use" request.SendFrame("Hello"); // Receive the reply message from the server. Note that // this ReceiveFrameString() call will block forever waiting // for a message. var reply = request.ReceiveFrameString(); Assert.That(reply == "World"); } }
static void Client(NetMQContext context) { using (NetMQSocket clientSocket = context.CreateRequestSocket()) { clientSocket.Connect("tcp://127.0.0.1:5555"); while (true) { Console.WriteLine("Please enter your message:"); string message = Console.ReadLine(); clientSocket.SendFrame(message); string answer = clientSocket.ReceiveFrameString(); Console.WriteLine("Answer from server: {0}", answer); if (message == "exit") { break; } } } }
private Task RunSubscriber(NetMQContext context) { using (NetMQSocket syncClient = context.CreateRequestSocket()) { syncClient.Connect(Pipe.PubSubControlBackAddressClient); syncClient.Send(string.Empty); syncClient.Receive(); var actions = new Dictionary<string, Delegate>(); actions.Add("MethodInfo", TestActors); actions.Add("ShutDownAllActors", ShutDownAllActors); using (var actor = new Actor<Order>(context, new BinarySerializer())) { actor.RegisterActor( "Display", string.Empty, "outRoute", null, new BinarySerializer(), new DefaultSerializer(Exchange.ControlChannelEncoding), actions); actor.StartAllActors(); } } return null; }
private void CreateClient(NetMQContext ctx, string prefix) { Task.Run(() => { var client = ctx.CreateRequestSocket(); clients.Add(client); client.Connect("tcp://127.0.0.1:5556"); client.Send(string.Format("{0}Hello", prefix)); //read client message var echoedServerMessage = client.ReceiveString(); Console.WriteLine( "\r\nClient Prefix is : '{0}', Server Message : '{1}'", prefix, echoedServerMessage); }); }
private void SetUpMonitorChannel(NetMQContext context) { this.MonitorChannel = context.CreateRequestSocket(); this.MonitorChannel.Connect(Pipe.MonitorAddressClient); }
public void Init(string hostAddress, string portNumber, string portNumber_info, bool shouldCreateTestClient, bool shouldCreateServer, bool debugNetworkMessages, bool logSimpleTimingInfo, bool logDetailedTimeInfo, string preferredImageFormat, bool saveDebugImageFiles, string environmentScene) { this.avatarPrefab = Resources.Load<Avatar>("Prefabs/Avatar"); if (this.avatarPrefab == null) { Debug.Log ("it doesnt exist still!"); } Debug.Log ("May have just printed something right here^"); Debug.Log (this.avatarPrefab.name); // Read port number this.portNumber = portNumber; this.portNumber_info = portNumber_info; this.hostAddress = hostAddress; this.shouldCreateTestClient = shouldCreateTestClient; this.shouldCreateServer = shouldCreateServer; this.debugNetworkMessages = debugNetworkMessages; logSimpleTimeInfo = logSimpleTimingInfo; logTimingInfo = logDetailedTimeInfo; CameraStreamer.preferredImageFormat = preferredImageFormat; // defaults to bmp this.saveDebugImageFiles = saveDebugImageFiles; // defaults to False this.environmentScene = environmentScene; // defaults to "Empty" // Load Environment Scene if (shouldCreateServer) { SceneManager.LoadScene (environmentScene, LoadSceneMode.Additive); if (!SceneManager.GetSceneByName (environmentScene).IsValid()) { Debug.LogWarning ("Scene name \"" + environmentScene + "\" was not found."); } } // Start up connections _ctx = NetMQContext.Create(); clientInfo = _ctx.CreateRequestSocket(); clientInfo.Options.Linger = TimeSpan.Zero; clientInfo.Connect("tcp://" + hostAddress + ":" + portNumber_info); CreateNewSocketConnection(); Debug.Log ("Net Messenger Initialized!"); }