/// <summary> /// Send response /// </summary> /// <param name="size"></param> protected void SendResponse(int size) { try { messageManager.Send(socket, responseObject, 0, size); } catch { responseObject.Dispose(); } }
public void SendMessage(Message msg, bool startTimer = false) { msg.ctrl = (byte)ESAFlag.Seq; UInt16 len = msg.GetLength(); msg.len = len; msg.seq = GetCliSeq(); _ringSendMsgAckBuffer[msg.seq] = msg; _sender.Send(msg); }
/// <summary> /// Send response /// </summary> /// <param name="size"></param> protected void SendResponse(int size) { var _r = responseObject; responseObject = null; try { messageManager.Send(socket, _r, 0, size); } catch { messageManager.Return(_r); } }
private void ChunkedSend(NetworkSender sender, byte[] buffer) { int tosend = buffer.Length; int pos = 0; while (tosend > 0) { int chunksize = tosend; if (chunksize > MaxMessageSize) { if (OnOverflow == OverflowAction.Discard) { return; } if (OnOverflow == OverflowAction.Error) { throw new OverflowException("Attempted to send a message larger than MaxMessageSize(" + MaxMessageSize + "). Actual size was: " + buffer.Length + ". Adjust OnOverflow and MaxMessageSize parameters accordingly."); } chunksize = MaxMessageSize; } sender.Send(buffer, pos, chunksize); tosend -= chunksize; pos += chunksize; } }
static void Main(string[] args) { Stack<String> container = new Stack<string>(); container.Push("Message 1"); container.Push("Message 2"); container.Push("Message 3"); container.Push(ConstantsHelper.ERROR_SIGNAL); container.Push("Message 4"); container.Push("Message 5"); INetworkSender<string> sender = new NetworkSender(new NetworkService()); sender.Sent += Sender_Sent; sender.AddToBuffer(container); sender.AddToBuffer("Message 6"); sender.AddToBuffer("Message 7"); //To find the error code generation find a comment. //"HACK: For generate error." try { sender.Send(); } catch (Exception ex) { Console.WriteLine(); Console.WriteLine(ex.ToString()); Console.WriteLine(); } sender.Send(); sender.Sent -= Sender_Sent; (sender as IDisposable)?.Dispose(); Console.ReadKey(); }
private void ChunkedSend(NetworkSender sender, byte[] buffer, AsyncContinuation continuation) { int tosend = buffer.Length; int pos = 0; AsyncContinuation sendNextChunk = null; sendNextChunk = ex => { if (ex != null) { continuation(ex); return; } InternalLogger.Trace("Sending chunk, position: {0}, length: {1}", pos, tosend); if (tosend <= 0) { continuation(null); return; } int chunksize = tosend; if (chunksize > MaxMessageSize) { if (OnOverflow == NetworkTargetOverflowAction.Discard) { InternalLogger.Trace("discard because chunksize > this.MaxMessageSize"); continuation(null); return; } if (OnOverflow == NetworkTargetOverflowAction.Error) { continuation(new OverflowException("Attempted to send a message larger than MaxMessageSize (" + MaxMessageSize + "). Actual size was: " + buffer.Length + ". Adjust OnOverflow and MaxMessageSize parameters accordingly.")); return; } chunksize = MaxMessageSize; } int pos0 = pos; tosend -= chunksize; pos += chunksize; sender.Send(buffer, pos0, chunksize, sendNextChunk); }; sendNextChunk(null); }
private void ChunkedSend(NetworkSender sender, byte[] buffer, AsyncContinuation continuation) { var tosend = buffer.Length; var pos = 0; AsyncContinuation sendNextChunk = null; sendNextChunk = ex => { if (ex != null) { continuation(ex); return; } if (tosend <= 0) { continuation(null); return; } var chunksize = tosend; if (chunksize > MaxMessageSize) { if (OnOverflow == NetworkTargetOverflowAction.Discard) { continuation(null); return; } if (OnOverflow == NetworkTargetOverflowAction.Error) { continuation(new OverflowException("Attempted to send a message larger than MaxMessageSize (" + MaxMessageSize + "). Actual size was: " + buffer.Length + ". Adjust OnOverflow and MaxMessageSize parameters accordingly.")); return; } chunksize = MaxMessageSize; } var pos0 = pos; tosend -= chunksize; pos += chunksize; sender.Send(buffer, pos0, chunksize, sendNextChunk); }; sendNextChunk(null); }
protected void SendResponse(int size) => messageManager.Send(socket, responseObject, 0, size);
private void ChunkedSend(NetworkSender sender, byte[] buffer, AsyncContinuation continuation) { int tosend = buffer.Length; if (tosend <= MaxMessageSize) { // Chunking is not needed, no need to perform delegate capture InternalLogger.Trace("Sending chunk, position: {0}, length: {1}", 0, tosend); if (tosend <= 0) { continuation(null); return; } sender.Send(buffer, 0, tosend, continuation); } else { int pos = 0; AsyncContinuation sendNextChunk = null; sendNextChunk = ex => { if (ex != null) { continuation(ex); return; } InternalLogger.Trace("NetworkTarget(Name={0}): Sending chunk, position: {1}, length: {2}", Name, pos, tosend); if (tosend <= 0) { continuation(null); return; } int chunksize = tosend; if (chunksize > MaxMessageSize) { if (OnOverflow == NetworkTargetOverflowAction.Discard) { InternalLogger.Trace("NetworkTarget(Name={0}): Discard because chunksize > this.MaxMessageSize", Name); continuation(null); return; } if (OnOverflow == NetworkTargetOverflowAction.Error) { continuation(new OverflowException($"Attempted to send a message larger than MaxMessageSize ({MaxMessageSize}). Actual size was: {buffer.Length}. Adjust OnOverflow and MaxMessageSize parameters accordingly.")); return; } chunksize = MaxMessageSize; } int pos0 = pos; tosend -= chunksize; pos += chunksize; sender.Send(buffer, pos0, chunksize, sendNextChunk); }; sendNextChunk(null); } }
// Send public void Send(ServerMessage messageType, params object[] arguments) { NetworkSender.Send(connectionId, (MessageType)messageType, arguments); }