CreateResponseSocket() private méthode

private CreateResponseSocket ( ) : ResponseSocket
Résultat ResponseSocket
Exemple #1
0
 public AsyncWorker(int id, NetMQContext context, string address) : base(id)
 {
     _responseSocket = context.CreateResponseSocket();
     _responseSocket.Options.ReceiveHighWatermark = 2;
     _responseSocket.Options.SendHighWatermark = 2;
     _responseSocket.Options.Identity = BitConverter.GetBytes(id);
     _responseSocket.Connect(address);
 }
Exemple #2
0
        public Heartbeat(ILog logger,  string address, NetMQContext context)
        {
            this.logger = logger;
            this.address = address;
            this.context = context;

            this.server = context.CreateResponseSocket();
            this.stopEvent = new ManualResetEventSlim();
        }
		public CommandListener (int port, Dictionary<int, Job> jobs)
		{
			this.Port = port;
			this.Jobs = jobs;
			this.Context = NetMQContext.Create ();
			this.RequestSock = Context.CreateResponseSocket ();
			this.RequestSock.Bind ("tcp://0.0.0.0:" + Port);
			logger.Info ("Bound to TCP port {0}", Port);

			this.ResponseSock = Context.CreatePushSocket ();
			this.ResponseSock.Bind ("tcp://0.0.0.0:" + (Port + 1));
			logger.Info ("Bound callback to TCP port {0}", (Port + 1));
		}
Exemple #4
0
        public void Bind()
        {
            context = NetMQContext.Create();

            if (socket != null)
            {
                throw new NetMQException("Attempt to set socket that was already defined. This would prevent successful dispose of the context later on (since we can no longer close all sockets).");
            }
            socket = context.CreateResponseSocket();
            socket.Options.Linger = new TimeSpan(0, 0, 0, 1);

            Trace.Assert(Protocol.ToLower().Equals("tcp"), "Only TCP is supported for now");

            socket.Bind("tcp://" + Host + ":" + Port);
        }
Exemple #5
0
        /// <summary>
        /// SimpleHelloWorldServer does the following:
        /// * Creates a Response socket
        /// * Waits for a "Hello" request
        /// * Sends a "World" reply
        /// </summary>
        /// <param name="context"></param>
        private void Server(NetMQContext context)
        {
            // create the response socket
            using (var response = context.CreateResponseSocket())
            {
                // bind the response socket, binds make the socket the "server"
                // * can be used to bind to all IP addresses
                response.Bind("tcp://*:5555");

                // response socket must first receive a message and only then reply
                string request = response.ReceiveFrameString();

                Assert.That(request == "Hello");

                response.SendFrame("World");
            }
        }
Exemple #6
0
        static void Server(NetMQContext context)
        {
            using (NetMQSocket serverSocket = context.CreateResponseSocket())
            {
                serverSocket.Bind("tcp://*:5555");

                while (true)
                {
                    string message = serverSocket.ReceiveFrameString();

                    Console.WriteLine("Receive message {0}", message);

                    serverSocket.SendFrame("World");

                    if (message == "exit")
                    {
                        break;
                    }
                }
            }
        }
Exemple #7
0
 private void InitZmq(string host, int port)
 {
     if (_ctx == null)
     {
         _ctx = NetMQContext.Create();
         _socket = _ctx.CreateResponseSocket();
         var address = string.Format("{0}:{1}", host, port);
         _socket.Bind(address);
         Log.InfoFormat(@"Context server running at: {0}", address);
     }
 }
Exemple #8
0
        private static void StartServerNetMq(NetMQContext context)
        {
            using (NetMQSocket serverSocket = context.CreateResponseSocket())
            {
                serverSocket.Options.SendTimeout = TimeSpan.FromMilliseconds(60000);

                serverSocket.Bind(string.Format("tcp://*:{0}", 2804));
                string message = string.Empty;
                string retMsg = string.Empty;

                Console.WriteLine("Server started;");

                while (true)
                {
                    //log.WriteLog("Received command {0}, {1} bytes returned.", message, results.Length);
                    try
                    {
                        message = serverSocket.ReceiveString();
                        //Console.WriteLine("Message: {0} received.", message);
                        if(message == "Who's there?")
                        {
                            TimeSpan timeSinceLast = DateTime.Now - lastVerification;

                            //if (verificationState == VerificationState.Verifying && timeSinceLast.TotalSeconds > 15)
                            //    name = string.Empty;

                            retMsg = name;
                        }

                        serverSocket.Send(retMsg);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Error sending data; message: {0}, error: {1}", message, e);
                        serverSocket.Send(string.Empty);
                    }
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="NmqResponseQueue"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="port">The port.</param>
 internal NmqResponseQueue(NetMQContext context, int port)
 {
     socket = context.CreateResponseSocket();
     var address = string.Format("tcp://127.0.0.1:{0}", port);
     socket.Bind(address);
 }