private static void ForwardTo(NetMQSocketEventArgs args, IOutgoingSocket toSocket) { var msg = new Msg(); msg.InitEmpty(); bool more; do { args.Socket.Receive(ref msg); more = msg.HasMore; toSocket.Send(ref msg, more); } while (more); msg.Close(); }
/// <summary> /// Send routing key over <paramref name="socket"/>. /// </summary> /// <param name="socket">the IOutgoingSocket to transmit on</param> /// <param name="routingKey">the routing key to send</param> public static void SendMoreFrame(this IOutgoingSocket socket, RoutingKey routingKey) { socket.SendMoreFrame(routingKey.Bytes); }
/// <summary> /// Transmit a specific status-signal over this socket that indicates there is an error. /// </summary> /// <param name="socket">the IOutgoingSocket to transmit on</param> public static void SignalError(this IOutgoingSocket socket) { socket.Signal(1); }
/// <summary> /// Transmit a specific status-signal over this socket that indicates OK. /// </summary> /// <param name="socket">the IOutgoingSocket to transmit on</param> public static void SignalOK(this IOutgoingSocket socket) { socket.Signal(0); }
/// <summary> /// Transmit an empty frame over this socket, block until frame is sent. /// Send more frame, another frame must be sent after this frame. Use to chain Send methods. /// </summary> /// <param name="socket">the IOutgoingSocket to transmit on</param> /// <returns>a reference to this IOutgoingSocket so that method-calls may be chained together</returns> public static IOutgoingSocket SendMoreFrameEmpty(this IOutgoingSocket socket) { SendFrame(socket, EmptyArray <byte> .Instance, true); return(socket); }
public static IOutgoingSocket SendMoreFrame([NotNull] this IOutgoingSocket socket, [NotNull] byte[] data) { SendFrame(socket, data, true); return(socket); }
/// <summary> /// Send the ZreMsg to the socket. /// </summary> public void Send(IOutgoingSocket output) { if (output is RouterSocket) output.SendMoreFrame(RoutingId); int frameSize = 2 + 1; // Signature and message ID switch (Id) { case MessageId.Hello: frameSize += Hello.GetFrameSize(); break; case MessageId.Whisper: frameSize += Whisper.GetFrameSize(); break; case MessageId.Shout: frameSize += Shout.GetFrameSize(); break; case MessageId.Join: frameSize += Join.GetFrameSize(); break; case MessageId.Leave: frameSize += Leave.GetFrameSize(); break; case MessageId.Ping: frameSize += Ping.GetFrameSize(); break; case MessageId.PingOk: frameSize += PingOk.GetFrameSize(); break; } // Now serialize message into the buffer Msg msg = new Msg(); msg.InitPool(frameSize); try { m_offset = 0; m_buffer = msg.Data; // put signature PutNumber2(0xAAA0 | 1); // put message id PutNumber1((byte)Id); switch (Id) { case MessageId.Hello: Hello.Write(this); break; case MessageId.Whisper: Whisper.Write(this); break; case MessageId.Shout: Shout.Write(this); break; case MessageId.Join: Join.Write(this); break; case MessageId.Leave: Leave.Write(this); break; case MessageId.Ping: Ping.Write(this); break; case MessageId.PingOk: PingOk.Write(this); break; } // Send the data frame output.Send(ref msg, false); } finally { m_buffer = null; msg.Close(); } }
/// <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> /// Attempt to transmit routing keys over <paramref name="socket"/>. /// If message cannot be sent immediately, return <c>false</c>. /// Routing is always sent as more frame. /// </summary> /// <param name="socket">the IOutgoingSocket to transmit on</param> /// <param name="routingKeys">the routing keys to send</param> /// <returns><c>true</c> if a message was available, otherwise <c>false</c>.</returns> public static bool TrySendRoutingKeys(this IOutgoingSocket socket, IEnumerable <RoutingKey> routingKeys) { return(socket.TrySendRoutingKeys(TimeSpan.Zero, routingKeys)); }
/// <summary> /// Send empty list of routing keys over <paramref name="socket"/>, append an empty message at the end of the keys. /// </summary> /// <param name="socket">the IOutgoingSocket to transmit on</param> public static IOutgoingSocket SendEmptyRoutingKeys(this IOutgoingSocket socket) { return(socket.SendMoreFrameEmpty()); }
/// <summary> /// Attempt to transmit routing key over <paramref name="socket"/>. /// If message cannot be sent within <paramref name="timeout"/>, return <c>false</c>. /// Routing is always sent as more frame. /// </summary> /// <param name="socket">the IOutgoingSocket to transmit on</param> /// <param name="timeout">The maximum period of time to try to send a message.</param> /// <param name="routingKey">the routing key to send</param> /// <returns><c>true</c> if a message was available, otherwise <c>false</c>.</returns> public static bool TrySendFrame(this IOutgoingSocket socket, TimeSpan timeout, RoutingKey routingKey) { return(socket.TrySendFrame(timeout, routingKey.Bytes, true)); }
/// <summary> /// Attempt to transmit an empty frame on <paramref cref="socket"/>. /// If message cannot be sent immediately, return <c>false</c>. /// </summary> /// <param name="socket">the IOutgoingSocket to transmit on</param> /// <param name="more">set this flag to true to signal that you will be immediately sending another frame (optional: default is false)</param> /// <returns><c>true</c> if a message was available, otherwise <c>false</c>.</returns> public static bool TrySendFrameEmpty([NotNull] this IOutgoingSocket socket, bool more = false) { return(TrySendFrame(socket, s_empty, more)); }
/// <summary> /// Transmit an empty frame over this socket, block until frame is sent. /// Send more frame, another frame must be sent after this frame. Use to chain Send methods. /// </summary> /// <param name="socket">the IOutgoingSocket to transmit on</param> public static void SendMoreFrameEmpty([NotNull] this IOutgoingSocket socket) { SendFrame(socket, s_empty, true); }
/// <summary> /// Transmit an empty frame over this socket, block until frame is sent. /// </summary> /// <param name="socket">the IOutgoingSocket to transmit on</param> /// <param name="more">set this flag to true to signal that you will be immediately sending another frame (optional: default is false)</param> public static void SendFrameEmpty([NotNull] this IOutgoingSocket socket, bool more = false) { SendFrame(socket, s_empty, more); }
/// <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> 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> /// Transmit a byte-array of data over this socket, block until frame is sent. /// Send more frame, another frame must be sent after this frame. Use to chain Send methods. /// </summary> /// <param name="socket">the IOutgoingSocket to transmit on</param> /// <param name="data">the byte-array of data to send</param> /// <param name="length">the number of bytes to send from <paramref name="data"/>.</param> /// <returns>a reference to this IOutgoingSocket so that method-calls may be chained together</returns> public static IOutgoingSocket SendMoreFrame(this IOutgoingSocket socket, byte[] data, int length) { SendFrame(socket, data, length, true); return(socket); }
/// <summary> /// Send the ZreMsg 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> public void Send(IOutgoingSocket output) { if (output is RouterSocket) output.SendMoreFrame(RoutingId); int frameSize = 2 + 1; // Signature and message ID switch (Id) { case MessageId.Hello: frameSize += Hello.GetFrameSize(); break; case MessageId.Whisper: frameSize += Whisper.GetFrameSize(); break; case MessageId.Shout: frameSize += Shout.GetFrameSize(); break; case MessageId.Join: frameSize += Join.GetFrameSize(); break; case MessageId.Leave: frameSize += Leave.GetFrameSize(); break; case MessageId.Ping: frameSize += Ping.GetFrameSize(); break; case MessageId.PingOk: frameSize += PingOk.GetFrameSize(); break; } // Now serialize message into the buffer Msg msg = new Msg(); msg.InitPool(frameSize); try { _offset = 0; _buffer = msg.Data; // put signature PutNumber2(0xAAA0 | 1); // put message id PutNumber1((byte) Id); switch (Id) { case MessageId.Hello: Hello.Write(this); break; case MessageId.Whisper: Whisper.Write(this); break; case MessageId.Shout: Shout.Write(this); break; case MessageId.Join: Join.Write(this); break; case MessageId.Leave: Leave.Write(this); break; case MessageId.Ping: Ping.Write(this); break; case MessageId.PingOk: PingOk.Write(this); break; } // Send the data frame var more = Id == MessageId.Whisper || Id == MessageId.Shout; output.TrySend(ref msg, TimeSpan.Zero, more); // Send message content for types with content switch (Id) { case MessageId.Whisper: if (Whisper.Content == null) { Whisper.Content = new NetMQMessage(); Whisper.Content.PushEmptyFrame(); } output.TrySendMultipartMessage(Whisper.Content); break; case MessageId.Shout: if (Shout.Content == null) { Shout.Content = new NetMQMessage(); Shout.Content.PushEmptyFrame(); } output.TrySendMultipartMessage(Shout.Content); break; } } finally { _buffer = null; msg.Close(); } }
/// <summary> /// Send the ZreMsg 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> public void Send(IOutgoingSocket output) { if (output is RouterSocket) { output.SendMoreFrame(RoutingId); } int frameSize = 2 + 1; // Signature and message ID switch (Id) { case MessageId.Hello: frameSize += Hello.GetFrameSize(); break; case MessageId.Whisper: frameSize += Whisper.GetFrameSize(); break; case MessageId.Shout: frameSize += Shout.GetFrameSize(); break; case MessageId.Join: frameSize += Join.GetFrameSize(); break; case MessageId.Leave: frameSize += Leave.GetFrameSize(); break; case MessageId.Ping: frameSize += Ping.GetFrameSize(); break; case MessageId.PingOk: frameSize += PingOk.GetFrameSize(); break; } // Now serialize message into the buffer Msg msg = new Msg(); msg.InitPool(frameSize); try { m_offset = 0; m_buffer = msg.Data; // put signature PutNumber2(0xAAA0 | 1); // put message id PutNumber1((byte)Id); switch (Id) { case MessageId.Hello: Hello.Write(this); break; case MessageId.Whisper: Whisper.Write(this); break; case MessageId.Shout: Shout.Write(this); break; case MessageId.Join: Join.Write(this); break; case MessageId.Leave: Leave.Write(this); break; case MessageId.Ping: Ping.Write(this); break; case MessageId.PingOk: PingOk.Write(this); break; } // Send the data frame var more = Id == MessageId.Whisper || Id == MessageId.Shout; output.TrySend(ref msg, TimeSpan.Zero, more); // Send message content for types with content switch (Id) { case MessageId.Whisper: if (Whisper.Content == null) { Whisper.Content = new NetMQMessage(); Whisper.Content.PushEmptyFrame(); } output.TrySendMultipartMessage(Whisper.Content); break; case MessageId.Shout: if (Shout.Content == null) { Shout.Content = new NetMQMessage(); Shout.Content.PushEmptyFrame(); } output.TrySendMultipartMessage(Shout.Content); break; } } finally { m_buffer = null; msg.Close(); } }
private static void ProxyBetween(IReceivingSocket from, IOutgoingSocket to, [CanBeNull] IOutgoingSocket control) { var msg = new Msg(); msg.InitEmpty(); var copy = new Msg(); copy.InitEmpty(); while (true) { from.Receive(ref msg); var more = msg.HasMore; if (control != null) { copy.Copy(ref msg); control.Send(ref copy, more); } to.Send(ref msg, more); if (!more) break; } copy.Close(); msg.Close(); }
public NodeActionScheduler(IUtcClock clock, IActionTimer timer, INodeMarshaller marshaller, IOutgoingSocket actorSocket) : base(clock, timer) { _marshaller = marshaller; _actorSocket = actorSocket; }
/// <summary> /// Transmit an empty frame over this socket, block until frame is sent. /// </summary> /// <param name="socket">the IOutgoingSocket to transmit on</param> /// <param name="more">set this flag to true to signal that you will be immediately sending another frame (optional: default is false)</param> public static void SendFrameEmpty(this IOutgoingSocket socket, bool more = false) { SendFrame(socket, EmptyArray <byte> .Instance, more); }
private static void Send(string message, IOutgoingSocket socket, bool sendMore = true) { socket.SendFrame(message, sendMore); }
/// <summary> /// Attempt to transmit an empty frame on <paramref name="socket"/>. /// If message cannot be sent immediately, return <c>false</c>. /// </summary> /// <param name="socket">the IOutgoingSocket to transmit on</param> /// <param name="more">set this flag to true to signal that you will be immediately sending another frame (optional: default is false)</param> /// <returns><c>true</c> if a message was available, otherwise <c>false</c>.</returns> public static bool TrySendFrameEmpty(this IOutgoingSocket socket, bool more = false) { return(TrySendFrame(socket, EmptyArray <byte> .Instance, more)); }
/// <summary> /// Attempt to transmit a single frame on <paramref name="socket"/>. /// If message cannot be sent within <paramref name="timeout"/>, return <c>false</c>. /// </summary> /// <param name="socket">the IOutgoingSocket to transmit on</param> /// <param name="timeout">The maximum period of time to try to send a message.</param> /// <param name="data">the byte-array of data to send</param> /// <param name="more">set this flag to true to signal that you will be immediately sending another frame (optional: default is false)</param> /// <returns><c>true</c> if a message was available, otherwise <c>false</c>.</returns> public static bool TrySendFrame(this IOutgoingSocket socket, TimeSpan timeout, byte[] data, bool more = false) { return(TrySendFrame(socket, timeout, data, data.Length, more)); }
/// <summary> /// Attempt to transmit a specific status-signal over this socket that indicates OK. /// If signal cannot be sent immediately, return <c>false</c>. /// </summary> /// <param name="socket">the IOutgoingSocket to transmit on</param> public static bool TrySignalOK(this IOutgoingSocket socket) { return(TrySignal(socket, 0)); }
/// <summary> /// Attempt to transmit a single frame on <paramref name="socket"/>. /// If message cannot be sent immediately, return <c>false</c>. /// </summary> /// <param name="socket">the IOutgoingSocket to transmit on</param> /// <param name="data">the byte-array of data to send</param> /// <param name="length">the number of bytes to send from <paramref name="data"/>.</param> /// <param name="more">set this flag to true to signal that you will be immediately sending another frame (optional: default is false)</param> /// <returns><c>true</c> if a message was available, otherwise <c>false</c>.</returns> public static bool TrySendFrame(this IOutgoingSocket socket, byte[] data, int length, bool more = false) { return(TrySendFrame(socket, TimeSpan.Zero, data, length, more)); }
/// <summary> /// Attempt to transmit a specific status-signal over this socket that indicates there is an error. /// If signal cannot be sent immediately, return <c>false</c>. /// </summary> /// <param name="socket">the IOutgoingSocket to transmit on</param> public static bool TrySignalError(this IOutgoingSocket socket) { return(socket.TrySignal(1)); }
/// <summary> /// Send multiple frames on <paramref name="socket"/>, blocking until all frames are sent. /// </summary> /// <param name="socket">the IOutgoingSocket to transmit on</param> /// <param name="frames">frames to transmit</param> public static void SendMultipartBytes(this IOutgoingSocket socket, params byte[][] frames) { SendMultipartBytes(socket, (IEnumerable <byte[]>)frames); }
/// <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> /// Block until the message can be sent. /// </summary> /// <remarks> /// The call blocks until the message can be sent and cannot be interrupted. /// Whether the message can be sent depends on the socket type. /// </remarks> /// <param name="socket">The socket to send the message on.</param> /// <param name="msg">An object with message's data to send.</param> /// <param name="more">Indicate if another frame is expected after this frame</param> public static void Send(this IOutgoingSocket socket, ref Msg msg, bool more) { var result = socket.TrySend(ref msg, SendReceiveConstants.InfiniteTimeout, more); Debug.Assert(result); }
/// <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> /// Attempt to transmit a multiple frames on <paramref name="socket"/>. /// If frames cannot be sent within <paramref name="timeout"/>, return <c>false</c>. /// </summary> /// <param name="socket">the IOutgoingSocket to transmit on</param> /// <param name="timeout">The maximum period of time to try to send a message.</param> /// <param name="frames">frames to transmit</param> public static bool TrySendMultipartBytes(this IOutgoingSocket socket, TimeSpan timeout, params byte[][] frames) { return(TrySendMultipartBytes(socket, timeout, (IEnumerable <byte[]>)frames)); }
/// <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); }
/// <summary> /// Attempt to transmit a multiple frames on <paramref name="socket"/>. /// If frames cannot be sent immediately, return <c>false</c>. /// </summary> /// <param name="socket">the IOutgoingSocket to transmit on</param> /// <param name="frames">frames to transmit</param> public static bool TrySendMultipartBytes(this IOutgoingSocket socket, IEnumerable <byte[]> frames) { return(TrySendMultipartBytes(socket, TimeSpan.Zero, frames)); }
/// <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> /// Transmit a string over this socket, block until frame is sent. /// Send more frame, another frame must be sent after this frame. Use to chain Send methods. /// </summary> /// <param name="socket">the IOutgoingSocket to transmit on</param> /// <param name="message">the string to send</param> /// <returns>a reference to this IOutgoingSocket so that method-calls may be chained together</returns> public static IOutgoingSocket SendMoreFrame(this IOutgoingSocket socket, string message) { SendFrame(socket, message, true); return(socket); }
/// <summary> /// Send the Codec to the socket. /// </summary> public void Send(IOutgoingSocket output) { if (output is RouterSocket) output.SendMoreFrame(RoutingId); int frameSize = 2 + 1; // Signature and message ID switch (Id) { case MessageId.Message: frameSize += Message.GetFrameSize(); break; case MessageId.ServiceRegister: frameSize += ServiceRegister.GetFrameSize(); break; case MessageId.Error: frameSize += Error.GetFrameSize(); break; } // Now serialize message into the buffer Msg msg = new Msg(); msg.InitPool(frameSize); try { m_offset = 0; m_buffer = msg.Data; // put signature PutNumber2(0xAAA0 | 0); // put message id PutNumber1((byte)Id); switch (Id) { case MessageId.Message: Message.Write(this); break; case MessageId.ServiceRegister: ServiceRegister.Write(this); break; case MessageId.Error: Error.Write(this); break; } // Send the data frame output.Send(ref msg, false); } finally { m_buffer = null; msg.Close(); } }
/// <summary> /// Transmit a byte-array of data over this socket, block until frame is sent. /// </summary> /// <param name="socket">the IOutgoingSocket to transmit on</param> /// <param name="data">the byte-array of data to send</param> /// <param name="more">set this flag to true to signal that you will be immediately sending another frame (optional: default is false)</param> public static void SendFrame(this IOutgoingSocket socket, byte[] data, bool more = false) { SendFrame(socket, data, data.Length, more); }
/// <summary> /// Send the Example to the socket. /// </summary> public void Send(IOutgoingSocket output) { if (output is RouterSocket) output.SendMore(RoutingId); int frameSize = 2 + 1; // Signature and message ID switch (Id) { case MessageId.Log: frameSize += 2; // Sequence frameSize += 2; // Version frameSize += 1; // Level frameSize += 1; // Event frameSize += 2; // Node frameSize += 2; // Peer frameSize += 8; // Time frameSize += 1 + Host.Length; frameSize += 4; if (Data != null) frameSize += Data.Length; break; case MessageId.Structures: frameSize += 2; // Sequence frameSize += 4; // Size is 4 octets if (Aliases != null) { foreach(string s in Aliases) { frameSize += 4 + s.Length; } } frameSize += 4; // Size is 4 octets if (Headers != null) { int headersSize = 0; foreach (var pair in Headers) { headersSize += 1 + pair.Key.Length; headersSize += 4 + pair.Value.Length; } frameSize += headersSize; } break; case MessageId.Binary: frameSize += 2; // Sequence frameSize += 4; // Flags frameSize += 4; // Size is 4 octets if (PublicKey != null) frameSize += PublicKey.Length; frameSize += 16; // Identifier break; case MessageId.Types: frameSize += 2; // Sequence frameSize += 1 + ClientForename.Length; frameSize += 1 + ClientSurname.Length; frameSize += 1 + ClientMobile.Length; frameSize += 1 + ClientEmail.Length; frameSize += 1 + SupplierForename.Length; frameSize += 1 + SupplierSurname.Length; frameSize += 1 + SupplierMobile.Length; frameSize += 1 + SupplierEmail.Length; break; } // Now serialize message into the buffer Msg msg = new Msg(); msg.InitPool(frameSize); try { m_offset = 0; m_buffer = msg.Data; // put signature PutNumber2(0xAAA0 | 0); // put message id PutNumber1((byte)Id); bool sendContent = false; int frames = 1; // Total number of frames to send switch (Id) { case MessageId.Log: PutNumber2(Sequence); PutNumber2(3); // Version PutNumber1(Level); PutNumber1(Event); PutNumber2(Node); PutNumber2(Peer); PutNumber8(Time); PutString(Host); if (Data != null) PutLongString(Data); else PutNumber4(0); // Empty string break; case MessageId.Structures: PutNumber2(Sequence); if (Aliases != null) { PutNumber4((UInt32)Aliases.Count); foreach (string s in Aliases) { PutLongString(s); } } else PutNumber4(0); // Empty string array if (Headers != null) { PutNumber4((UInt32)Headers.Count); foreach(var pair in Headers) { PutString(pair.Key); PutLongString(pair.Value); } } else PutNumber4(0); // Empty dictionary break; case MessageId.Binary: PutNumber2(Sequence); PutOctets(Flags, 4); if (PublicKey != null) { PutNumber4((UInt32)PublicKey.Length); Buffer.BlockCopy(PublicKey, 0, m_buffer, m_offset, PublicKey.Length); m_offset += PublicKey.Length; } else PutNumber4(0); // Empty chunk // copy guid Buffer.BlockCopy(Identifier.ToByteArray(), 0, m_buffer, m_offset, 16); m_offset += 16; frames++; frames += Content != null ? Content.FrameCount : 1; sendContent = true; break; case MessageId.Types: PutNumber2(Sequence); PutString(ClientForename); PutString(ClientSurname); PutString(ClientMobile); PutString(ClientEmail); PutString(SupplierForename); PutString(SupplierSurname); PutString(SupplierMobile); PutString(SupplierEmail); break; } // Now send the data frame output.Send(ref msg, --frames == 0 ? SendReceiveOptions.None : SendReceiveOptions.SendMore); // Now send any frame fields, in order if (Id == MessageId.Binary) { if (--frames == 0) output.Send(Address != null ? Address : new byte[0]); else output.SendMore(Address != null ? Address : new byte[0]); } // Now send the Content if necessary if (sendContent) { if (Content != null) { output.SendMessage(Content); } else output.Send(new byte[0]); } } finally { m_buffer = null; msg.Close(); } }
/// <summary> /// Attempt to transmit a single string frame on <paramref name="socket"/>. /// If message cannot be sent immediately, return <c>false</c>. /// </summary> /// <param name="socket">the IOutgoingSocket to transmit on</param> /// <param name="message">the string to send</param> /// <param name="more">set this flag to true to signal that you will be immediately sending another frame (optional: default is false)</param> /// <returns><c>true</c> if a message was available, otherwise <c>false</c>.</returns> public static bool TrySendFrame(this IOutgoingSocket socket, string message, bool more = false) { return(TrySendFrame(socket, TimeSpan.Zero, message, more)); }
/// <summary> /// Attempt to transmit a multiple message on <paramref name="socket"/>. /// If frames cannot be sent immediately, return <c>false</c>. /// </summary> /// <param name="socket">the IOutgoingSocket to transmit on</param> /// <param name="message">message to transmit</param> public static bool TrySendMultipartMessage(this IOutgoingSocket socket, NetMQMessage message) { return(TrySendMultipartMessage(socket, TimeSpan.Zero, message)); }
public static IOutgoingSocket SendMore([NotNull] this IOutgoingSocket socket, [NotNull] string message, [NotNull] Encoding encoding, bool dontWait = false) { socket.Send(message, encoding, dontWait, true); return(socket); }