protected virtual void OnRecievDataCallback(IAsyncResult result) { SocketContainer container = (SocketContainer)result.AsyncState; int bytesRecieved = 0; try { bytesRecieved = container.ConnectionSocket.EndReceive(result); } catch (SocketException ex) { if (OnWrite != null) { OnWrite(string.Format("[SERVER] - {0}", ex.Message)); } } string buff = Encoding.UTF8.GetString(container.Buffer, 0, bytesRecieved); string cont = string.Format("[SERVER {0}] - Received message: ", Port) + buff; ProcessMsg(buff); OnWrite(cont); RecieveData(container.ConnectionSocket); }
private void SendingData(SocketContainer container, int currentPosition) { IAsyncResult result = container .ConnectionSocket .BeginSend(container.Buffer, 0, currentPosition + 1, SocketFlags.None, new AsyncCallback(OnSendingCallback), container); }
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 {1}] - {0}", ex.Message, Id)); } }
public void _OnRecievingCallback(IAsyncResult result) { SocketContainer container = (SocketContainer)result.AsyncState; int bytesRecieved = 0; try { bytesRecieved = container.ConnectionSocket.EndReceive(result); } catch (SocketException ex) { OnWrite(string.Format("[CLIENT {1}] - {0}", ex.Message, Id)); } OnWrite(string.Format("[SERVER] - {0}", Encoding.UTF8.GetString(container.Buffer, 0, bytesRecieved))); StartRecieving(container.ConnectionSocket); }
private void OnSendingCallback(IAsyncResult result) { SocketContainer container = (SocketContainer)result.AsyncState; int bytesSent = 0; try { bytesSent = container.ConnectionSocket.EndSend(result); if (OnWrite != null) { OnWrite(string.Format("[SERVER {1}] - Sent {0} bytes\n", bytesSent, Port)); } } catch (SocketException ex) { if (OnWrite != null) { OnWrite(string.Format("[SERVER] - {0}", ex.Message)); } } }
protected virtual void RecieveData(Socket connectedSocket) { byte[] buffer = new byte[8192]; SocketContainer container = new SocketContainer(connectedSocket, buffer); IAsyncResult result = connectedSocket.BeginReceive(container.Buffer, 0, container.Buffer.Length, SocketFlags.None, new AsyncCallback(OnRecievDataCallback), container); }
private void StartRecieving(Socket socket) { byte[] buffer = new byte[8192]; var container = new SocketContainer(socket, buffer); IAsyncResult result = socket.BeginReceive(buffer, 0, 8192, SocketFlags.None, new AsyncCallback(_OnRecievingCallback), container); }