Пример #1
0
        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);
        }
Пример #2
0
        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));
            }
        }