protected void StartSending(Socket socket, string msg) { byte[] buffer = Encoding.ASCII.GetBytes(msg); SocketContainer container = new SocketContainer(socket, buffer); socket.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(_OnSendingCallback), container); }
protected void _OnSendingCallback(IAsyncResult result) { SocketContainer container = (SocketContainer)result.AsyncState; int bytesSent = 0; try { bytesSent = container.ConnectionSocket.EndSend(result); } catch (SocketException ex) { Console.WriteLine(string.Format($"[CLIENT {_id}] - {0}", ex.Message)); } }