static void OnReceive(Udp udp, IDatagramReadCompletion completion) { if (completion.Error != null) { completion.Dispose(); Console.WriteLine($"{nameof(EchoServer)} receive error {completion.Error}"); udp.ReceiveStop(); udp.CloseHandle(OnClose); return; } ReadableBuffer data = completion.Data; string message = data.ReadString(Encoding.UTF8); data.Dispose(); IPEndPoint remoteEndPoint = completion.RemoteEndPoint; if (string.IsNullOrEmpty(message) || remoteEndPoint == null) { return; } WritableBuffer buffer = WritableBuffer.From(Encoding.UTF8.GetBytes(message)); udp.QueueSend(buffer, remoteEndPoint, OnSendCompleted); }
static void OnReceive(Udp udp, IDatagramReadCompletion completion) { if (completion.Error != null) { Console.WriteLine($"Echo server receive error {completion.Error}"); udp.CloseHandle(OnClosed); return; } IPEndPoint remoteEndPoint = completion.RemoteEndPoint; ReadableBuffer data = completion.Data; string message = data.Count > 0 ? data.ReadString(data.Count, Encoding.UTF8) : null; if (string.IsNullOrEmpty(message)) { return; } Console.WriteLine($"Echo server received : {message} from {remoteEndPoint}"); Console.WriteLine($"Echo server sending echo back to {remoteEndPoint}."); byte[] array = Encoding.UTF8.GetBytes($"ECHO [{message}]"); WritableBuffer buffer = WritableBuffer.From(array); udp.QueueSend(buffer, remoteEndPoint, OnSendCompleted); }
void OnReceive(Udp udp, IDatagramReadCompletion completion) { if (completion.Error != null || completion.RemoteEndPoint == null) { return; } ReadableBuffer buffer = completion.Data; if (buffer.Count == 0) { return; } string message = buffer.ReadString(buffer.Count, Encoding.UTF8); if (message == "PING" || message == "PANG") { this.serverReceiveCount++; } if (this.serverReceiveCount == 2) { udp.CloseHandle(this.OnClose); } }
void OnReceive(Udp udp, IDatagramReadCompletion completion) { var error = completion.Error as OperationException; if (error != null && error.ErrorCode == ErrorCode.ECANCELED) // UV_ECANCELED { return; } ReadableBuffer data = completion.Data; if (data.Count == 0) { return; } string message = data.ReadString(data.Count, Encoding.UTF8); if (message != ExpectedMessage) { Console.WriteLine( $"Udp pummel {this.numberOfSenders}v{this.numberOfReceivers} failed, wrong message '{message}' received."); } this.receiveCount++; }
void OnReceive(Udp udp, IDatagramReadCompletion completion) { if (completion.Error == null && completion.Data.Count > 0) { this.receiveCount++; } }
void OnClientReceive(Udp udp, IDatagramReadCompletion completion) { ReadableBuffer buffer = completion.Data; string message = buffer.ReadString(Encoding.UTF8); if (message == "PONG") { this.clientReceiveCount++; } udp.CloseHandle(this.OnClose); }
static void OnReceive(Udp udp, IDatagramReadCompletion completion) { if (completion.Error != null) { Console.WriteLine($"Echo client receive error {completion.Error}"); } IPEndPoint remoteEndPoint = completion.RemoteEndPoint; ReadableBuffer data = completion.Data; string message = data.ReadString(Encoding.UTF8); Console.WriteLine($"Echo client received : {message} from {remoteEndPoint}"); udp.CloseHandle(OnClosed); }
void OnClientReceive(Udp udp, IDatagramReadCompletion completion) { this.receiveError = completion.Error; ReadableBuffer buffer = completion.Data; string message = buffer.ReadString(Encoding.UTF8); if (message == "PING") { this.clientReceiveCount++; } /* we are done with the client handle, we can close it */ udp.CloseHandle(this.OnClose); }
void OnServerReceive(Udp udp, IDatagramReadCompletion completion) { ReadableBuffer buffer = completion.Data; string message = buffer.ReadString(Encoding.UTF8); if (message == "PING") { this.serverReceiveCount++; } udp.ReceiveStop(); byte[] data = Encoding.UTF8.GetBytes("PONG"); udp.QueueSend(data, completion.RemoteEndPoint, this.OnServerSendCompleted); }
void OnServerReceive(Udp udp, IDatagramReadCompletion completion) { this.receiveError = completion.Error; ReadableBuffer data = completion.Data; string message = data.ReadString(Encoding.UTF8); if (message == "EXIT") { this.serverReceiveCount++; } udp.CloseHandle(this.OnClose); this.client?.CloseHandle(this.OnClose); this.server.ReceiveStop(); this.server.CloseHandle(this.OnClose); }
void OnReceive(Udp udp, IDatagramReadCompletion completion) { if (completion.Error is OperationException error && error.ErrorCode == ErrorCode.ECANCELED) // UV_ECANCELED { return; } ReadableBuffer data = completion.Data; string message = data.ReadString(Encoding.UTF8); if (!string.IsNullOrEmpty(message) && message != ExpectedMessage) { Console.WriteLine($"Udp pummel {this.numberOfSenders}v{this.numberOfReceivers} failed, wrong message '{message}' received."); } this.receiveCount++; }
void OnReceive(Udp udp, IDatagramReadCompletion completion) { if (completion.Error == null) { ReadableBuffer data = completion.Data; if (data.Count == 0) { return; } IPEndPoint localEndPoint = udp.GetLocalEndPoint(); if (Equals(localEndPoint.Address, IPAddress.Any) && localEndPoint.Port == Port) { this.connectionCount++; } } udp.CloseHandle(this.OnClose); }
void OnReceive(Udp udp, IDatagramReadCompletion completion) { this.receiveError = completion.Error; this.clientReceiveCount++; }
void OnReceive(Udp udp, IDatagramReadCompletion datagramReadCompletion) => this.callbackCount++;