Beispiel #1
0
            public void RouterMessage(ZMessage reply)
            {
                // This method processes one message from a connected
                // server:

                // Frame 0 is server that replied
                string endpoint = reply.PopString();
                Server server   = this.Servers.Single(s => s.Endpoint == endpoint);

                if (!server.Alive)
                {
                    this.Actives.Add(server);
                    server.Refresh(true);
                }

                // Frame 1 may be sequence number for reply
                int sequence = reply.PopInt32();

                if (sequence == this.sequence)
                {
                    reply.Prepend(new ZFrame("OK"));

                    this.Pipe.Send(reply);

                    this.Request.Dispose();
                    this.Request = null;
                }
            }
Beispiel #2
0
        public void PopString()
        {
            const string test = "__TEST__";
            var          msg  = new ZMessage {
                new ZFrame(test)
            };

            Assert.AreEqual(test, msg.PopString());
        }
Beispiel #3
0
            public void ControlMessage(ZMessage msg)
            {
                // This method processes one message from our frontend class
                // (it's going to be CONNECT or REQUEST):

                string command = msg.PopString();

                if (command == "CONNECT")
                {
                    string endpoint = msg.PopString();
                    Console.WriteLine("I: connecting to {0}...", endpoint);

                    Router.Connect(endpoint);

                    var server = new Server(endpoint);
                    this.Servers.Add(server);
                    this.Actives.Add(server);
                }
                else if (command == "REQUEST")
                {
                    if (this.Request != null)
                    {
                        // Strict request-reply cycle
                        throw new InvalidOperationException();
                    }

                    // Prefix request with sequence number and empty envelope
                    msg.Prepend(new ZFrame(++sequence));

                    // Take ownership of request message
                    this.Request = msg.Duplicate();

                    // Request expires after global timeout
                    this.Expires = DateTime.UtcNow + GLOBAL_TIMEOUT;
                }
            }
Beispiel #4
0
			public void RouterMessage(ZMessage reply)
			{
				// This method processes one message from a connected
				// server:

				// Frame 0 is server that replied
				string endpoint = reply.PopString();
				Server server = this.Servers.Single(s => s.Endpoint == endpoint);
				if (!server.Alive)
				{
					this.Actives.Add(server);
					server.Refresh(true);
				}

				// Frame 1 may be sequence number for reply
				int sequence = reply.PopInt32();
				if (sequence == this.sequence)
				{
					reply.Prepend(new ZFrame("OK"));

					this.Pipe.Send(reply);

					this.Request.Dispose();
					this.Request = null;
				}
			}
Beispiel #5
0
			public void ControlMessage(ZMessage msg)
			{
				// This method processes one message from our frontend class
				// (it's going to be CONNECT or REQUEST):

				string command = msg.PopString();

				if (command == "CONNECT")
				{
					string endpoint = msg.PopString();
					Console.WriteLine("I: connecting to {0}...", endpoint);

					this.Router.Connect(endpoint);

					var server = new Server(endpoint);
					this.Servers.Add(server);
					this.Actives.Add(server);
				}
				else if (command == "REQUEST")
				{
					if (this.Request != null)
					{
						// Strict request-reply cycle
						throw new InvalidOperationException();
					}

					// Prefix request with sequence number and empty envelope
					msg.Prepend(new ZFrame(++sequence));

					// Take ownership of request message
					this.Request = msg.Duplicate();

					// Request expires after global timeout
					this.Expires = DateTime.UtcNow + GLOBAL_TIMEOUT;
				}
			}