public Send ( IOutgoingSocket output ) : bool | ||
output | IOutgoingSocket | |
Résultat | bool |
/// <summary> /// Send message to peer /// </summary> /// <param name="msg">the message</param> /// <returns>always true</returns> public bool Send(ZreMsg msg) { if (m_connected) { msg.Sequence = m_sentSequence++; msg.Send(m_mailbox); } return(true); }
/// <summary> /// Send a PingOk message to the socket /// </summary> /// <param name="socket"></param> /// <param name="sequence"></param> public static void SendPingOk(IOutgoingSocket socket, ushort sequence) { var msg = new ZreMsg { Id = MessageId.PingOk, PingOk = { Version = 2, Sequence = sequence, } }; msg.Send(socket); }
/// <summary> /// Send message to peer /// </summary> /// <param name="msg">the message</param> /// <returns>always true</returns> internal bool Send(ZreMsg msg) { if (Connected) { msg.Sequence = ++_sentSequence; _loggerDelegate?.Invoke($"{nameof(ZyrePeer)}.{nameof(Send)}() sending message={msg} to Endpoint={Endpoint}"); var success = msg.Send(_mailbox); if (!success) { _loggerDelegate?.Invoke($"{nameof(ZyrePeer)}.{nameof(Send)}() UNABLE to send message={msg} to Endpoint={Endpoint}"); } } return(true); }
/// <summary> /// Send a Ping message to the socket /// </summary> /// <param name="socket"></param> /// <param name="sequence"></param> /// <returns>true if message was successfully sent</returns> public static bool SendPing(IOutgoingSocket socket, ushort sequence) { var msg = new ZreMsg { Id = MessageId.Ping, Ping = { Version = 2, Sequence = sequence, } }; return(msg.Send(socket)); }
/// <summary> /// Send a Whisper message to the socket /// Warning re WHISPER and SHOUT: The 0MQ spec http://rfc.zeromq.org/spec:36 /// says "message content defined as one 0MQ frame. ZRE does not support multi-frame message contents." /// ...on the other hand, it appears that zeromq/zyre also supports multi-frame contents, as per the top of zyre.c /// This C# implementation allows multi-frame contents. /// </summary> /// <param name="socket"></param> /// <param name="sequence"></param> /// <param name="content">See warning above</param> /// <returns>true if message was successfully sent</returns> public static bool SendWhisper(IOutgoingSocket socket, ushort sequence, NetMQMessage content) { var msg = new ZreMsg { Id = MessageId.Whisper, Whisper = { Version = 2, Sequence = sequence, Content = content } }; return(msg.Send(socket)); }
/// <summary> /// Send a Shout message to the socket /// Warning re WHISPER and SHOUT: The 0MQ spec http://rfc.zeromq.org/spec:36 /// says "message content defined as one 0MQ frame. ZRE does not support multi-frame message contents." /// </summary> /// <param name="socket"></param> /// <param name="sequence"></param> /// <param name="content">See warning above</param> public static void SendShout(IOutgoingSocket socket, ushort sequence, NetMQMessage content) { var msg = new ZreMsg { Id = MessageId.Shout, Shout = { Version = 2, Sequence = sequence, Content = content } }; msg.Send(socket); }
/// <summary> /// Send a Leave message to the socket /// </summary> /// <param name="socket"></param> /// <param name="sequence"></param> /// <param name="group"></param> /// <param name="status"></param> public static void SendLeave(IOutgoingSocket socket, ushort sequence, string group, byte status) { var msg = new ZreMsg { Id = MessageId.Leave, Leave = { Version = 2, Sequence = sequence, Group = group, Status = status, } }; msg.Send(socket); }
/// <summary> /// Send a Join message to the socket /// </summary> /// <param name="socket"></param> /// <param name="sequence"></param> /// <param name="group"></param> /// <param name="status"></param> /// <returns>true if message was successfully sent</returns> public static bool SendJoin(IOutgoingSocket socket, ushort sequence, string group, byte status) { var msg = new ZreMsg { Id = MessageId.Join, Join = { Version = 2, Sequence = sequence, Group = group, Status = status, } }; return(msg.Send(socket)); }
/// <summary> /// Send a Hello message to the socket /// </summary> /// <param name="socket"></param> /// <param name="endpoint"></param> /// <param name="groups"></param> /// <param name="status"></param> /// <param name="name"></param> /// <param name="headers"></param> /// <returns>true if message was successfully sent</returns> public static bool SendHello(IOutgoingSocket socket, string endpoint, List <string> groups, byte status, string name, Dictionary <string, string> headers) { var msg = new ZreMsg { Id = MessageId.Hello, Hello = { Endpoint = endpoint, Groups = groups, Status = status, Name = name, Headers = headers } }; return(msg.Send(socket)); }
/// <summary> /// Send a Hello message to the socket /// </summary> /// <param name="socket"></param> /// <param name="sequence"></param> /// <param name="endpoint"></param> /// <param name="groups"></param> /// <param name="status"></param> /// <param name="name"></param> /// <param name="headers"></param> public static void SendHello(IOutgoingSocket socket, ushort sequence, string endpoint, List <string> groups, byte status, string name, Dictionary <string, string> headers) { var msg = new ZreMsg { Id = MessageId.Hello, Hello = { Version = 2, Sequence = sequence, Endpoint = endpoint, Groups = groups, Status = status, Name = name, Headers = headers } }; msg.Send(socket); }
/// <summary> /// Send a Ping message to the socket /// </summary> /// <param name="socket"></param> /// <param name="sequence"></param> /// <returns>true if message was successfully sent</returns> public static bool SendPing(IOutgoingSocket socket, ushort sequence) { var msg = new ZreMsg { Id = MessageId.Ping, Ping = { Version = 2, Sequence = sequence, } }; return msg.Send(socket); }
/// <summary> /// Send a Join message to the socket /// </summary> /// <param name="socket"></param> /// <param name="sequence"></param> /// <param name="group"></param> /// <param name="status"></param> /// <returns>true if message was successfully sent</returns> public static bool SendJoin(IOutgoingSocket socket, ushort sequence, string group, byte status) { var msg = new ZreMsg { Id = MessageId.Join, Join = { Version = 2, Sequence = sequence, Group = group, Status = status, } }; return msg.Send(socket); }
/// <summary> /// Send a Whisper message to the socket /// Warning re WHISPER and SHOUT: The 0MQ spec http://rfc.zeromq.org/spec:36 /// says "message content defined as one 0MQ frame. ZRE does not support multi-frame message contents." /// ...on the other hand, it appears that zeromq/zyre also supports multi-frame contents, as per the top of zyre.c /// This C# implementation allows multi-frame contents. /// </summary> /// <param name="socket"></param> /// <param name="sequence"></param> /// <param name="content">See warning above</param> /// <returns>true if message was successfully sent</returns> public static bool SendWhisper(IOutgoingSocket socket, ushort sequence, NetMQMessage content) { var msg = new ZreMsg { Id = MessageId.Whisper, Whisper = { Version = 2, Sequence = sequence, Content = content } }; return msg.Send(socket); }
/// <summary> /// Send a Leave message to the socket /// </summary> /// <param name="socket"></param> /// <param name="sequence"></param> /// <param name="group"></param> /// <param name="status"></param> public static void SendLeave(IOutgoingSocket socket, ushort sequence, string group, byte status) { var msg = new ZreMsg { Id = MessageId.Leave, Leave = { Version = 2, Sequence = sequence, Group = group, Status = status, } }; msg.Send(socket); }
public void HelloTest() { Action<ZreMsg> setMessage = m => { m.Id = ZreMsg.MessageId.Hello; m.Hello.Sequence = 123; m.Hello.Endpoint = "Life is short but Now lasts for ever"; m.Hello.Groups = new List<string>(); m.Hello.Groups.Add("Name: Brutus"); m.Hello.Groups.Add("Age: 43"); m.Hello.Status = 123; m.Hello.Name = "Life is short but Now lasts for ever"; m.Hello.Headers = new Dictionary<string,string>(); m.Hello.Headers.Add("Name", "Brutus"); m.Hello.Headers.Add("Age", "43"); }; Action<ZreMsg> checkMessage = m=> { Assert.That(m.Id, Is.EqualTo(ZreMsg.MessageId.Hello)); Assert.That(m.Hello.Sequence, Is.EqualTo(123)); Assert.That(m.Hello.Endpoint, Is.EqualTo("Life is short but Now lasts for ever")); Assert.That(m.Hello.Groups.Count, Is.EqualTo(2)); Assert.That(m.Hello.Groups[0], Is.EqualTo("Name: Brutus")); Assert.That(m.Hello.Groups[1], Is.EqualTo("Age: 43")); Assert.That(m.Hello.Status, Is.EqualTo(123)); Assert.That(m.Hello.Name, Is.EqualTo("Life is short but Now lasts for ever")); Assert.That(m.Hello.Headers.Count, Is.EqualTo(2)); Assert.That(m.Hello.Headers["Name"], Is.EqualTo("Brutus")); Assert.That(m.Hello.Headers["Age"], Is.EqualTo("43")); }; using (NetMQContext context = NetMQContext.Create()) using (var client = context.CreateDealerSocket()) using (var server = context.CreateRouterSocket()) { server.Bind("inproc://zprototest"); client.Connect("inproc://zprototest"); ZreMsg clientMessage = new ZreMsg(); ZreMsg serverMessage = new ZreMsg(); for (int i=0; i < 2; i++) { // client send message to server setMessage(clientMessage); clientMessage.Send(client); // server receive the message serverMessage.Receive(server); // check that message received ok Assert.That(serverMessage.RoutingId, Is.Not.Null); checkMessage(serverMessage); // reply to client, no need to set the message, using client data serverMessage.Send(server); // client receive the message clientMessage.Receive(client); // check that message received ok Assert.That(clientMessage.RoutingId, Is.Null); checkMessage(clientMessage); } } }
/// <summary> /// Send a Hello message to the socket /// </summary> /// <param name="socket"></param> /// <param name="endpoint"></param> /// <param name="groups"></param> /// <param name="status"></param> /// <param name="name"></param> /// <param name="headers"></param> public static void SendHello(IOutgoingSocket socket, string endpoint, List<string> groups, byte status, string name, Dictionary<string, string> headers) { var msg = new ZreMsg { Id = MessageId.Hello, Hello = { Endpoint = endpoint, Groups = groups, Status = status, Name = name, Headers = headers } }; msg.Send(socket); }
/// <summary> /// Send a Shout message to the socket /// Warning re WHISPER and SHOUT: The 0MQ spec http://rfc.zeromq.org/spec:36 /// says "message content defined as one 0MQ frame. ZRE does not support multi-frame message contents." /// But this C# implementation allows multi-frame contents. /// </summary> /// <param name="socket"></param> /// <param name="sequence"></param> /// <param name="content">See warning above</param> public static void SendShout(IOutgoingSocket socket, ushort sequence, NetMQMessage content) { var msg = new ZreMsg { Id = MessageId.Shout, Shout = { Version = 2, Sequence = sequence, Content = content } }; msg.Send(socket); }
public void LeaveTest() { Action<ZreMsg> setMessage = m => { m.Id = ZreMsg.MessageId.Leave; m.Leave.Sequence = 123; m.Leave.Group = "Life is short but Now lasts for ever"; m.Leave.Status = 123; }; Action<ZreMsg> checkMessage = m=> { Assert.That(m.Id, Is.EqualTo(ZreMsg.MessageId.Leave)); Assert.That(m.Leave.Sequence, Is.EqualTo(123)); Assert.That(m.Leave.Group, Is.EqualTo("Life is short but Now lasts for ever")); Assert.That(m.Leave.Status, Is.EqualTo(123)); }; using (NetMQContext context = NetMQContext.Create()) using (var client = context.CreateDealerSocket()) using (var server = context.CreateRouterSocket()) { server.Bind("inproc://zprototest"); client.Connect("inproc://zprototest"); ZreMsg clientMessage = new ZreMsg(); ZreMsg serverMessage = new ZreMsg(); for (int i=0; i < 2; i++) { // client send message to server setMessage(clientMessage); clientMessage.Send(client); // server receive the message serverMessage.Receive(server); // check that message received ok Assert.That(serverMessage.RoutingId, Is.Not.Null); checkMessage(serverMessage); // reply to client, no need to set the message, using client data serverMessage.Send(server); // client receive the message clientMessage.Receive(client); // check that message received ok Assert.That(clientMessage.RoutingId, Is.Null); checkMessage(clientMessage); } } }
/// <summary> /// Send a PingOk message to the socket /// </summary> /// <param name="socket"></param> /// <param name="sequence"></param> public static void SendPingOk(IOutgoingSocket socket, ushort sequence) { var msg = new ZreMsg { Id = MessageId.PingOk, PingOk = { Version = 2, Sequence = sequence, } }; msg.Send(socket); }
public void WhisperTest() { Action<ZreMsg> setMessage = m => { m.Id = ZreMsg.MessageId.Whisper; m.Whisper.Sequence = 123; }; Action<ZreMsg> checkMessage = m=> { Assert.That(m.Id, Is.EqualTo(ZreMsg.MessageId.Whisper)); Assert.That(m.Whisper.Sequence, Is.EqualTo(123)); Assert.That(m.Whisper.Content.FrameCount, Is.EqualTo(1)); }; using (NetMQContext context = NetMQContext.Create()) using (var client = context.CreateDealerSocket()) using (var server = context.CreateRouterSocket()) { server.Bind("inproc://zprototest"); client.Connect("inproc://zprototest"); ZreMsg clientMessage = new ZreMsg(); ZreMsg serverMessage = new ZreMsg(); for (int i=0; i < 2; i++) { // client send message to server setMessage(clientMessage); clientMessage.Send(client); // server receive the message serverMessage.Receive(server); // check that message received ok Assert.That(serverMessage.RoutingId, Is.Not.Null); checkMessage(serverMessage); // reply to client, no need to set the message, using client data serverMessage.Send(server); // client receive the message clientMessage.Receive(client); // check that message received ok Assert.That(clientMessage.RoutingId, Is.Null); checkMessage(clientMessage); } } }
/// <summary> /// Send message to peer /// </summary> /// <param name="msg">the message</param> /// <returns>always true</returns> internal bool Send(ZreMsg msg) { if (Connected) { msg.Sequence = ++_sentSequence; _loggerDelegate?.Invoke($"{nameof(ZyrePeer)}.{nameof(Send)}() sending message={msg} to Endpoint={Endpoint}"); var success = msg.Send(_mailbox); if (!success) { _loggerDelegate?.Invoke($"{nameof(ZyrePeer)}.{nameof(Send)}() UNABLE to send message={msg} to Endpoint={Endpoint}"); } } return true; }
/// <summary> /// Send message to peer /// </summary> /// <param name="msg">the message</param> /// <returns>always true</returns> public bool Send(ZreMsg msg) { if (_connected) { msg.Sequence = _sentSequence++; msg.Send(_mailbox); } return true; }