protected override void onReceived(IAsyncResult ar) { ReceiveVO receiveVO = (ReceiveVO)ar.AsyncState; int num = 0; try { num = receiveVO.socket.EndReceive(ar); } catch (SocketException) { } if (num == 0) { if (receiveVO.socket.Connected) { this.disconnectedByRemote(receiveVO.socket); return; } } else { string text = AbstractTcpSocket.keyForEndPoint((IPEndPoint)receiveVO.socket.RemoteEndPoint); this._logger.Debug(string.Concat(new object[] { "Client received ", num, " bytes from ", text })); base.triggerOnReceived(receiveVO, num); base.receive(receiveVO); } }
void onConnected(IAsyncResult ar) { Socket socket = (Socket)ar.AsyncState; bool flag = false; try { socket.EndConnect(ar); flag = true; } catch (SocketException ex) { this._logger.Error(ex.Message); } if (flag) { IPEndPoint endPoint = (IPEndPoint)socket.RemoteEndPoint; this._logger.Debug("Client connected to " + AbstractTcpSocket.keyForEndPoint(endPoint)); base.receive(new ReceiveVO(socket, new byte[socket.ReceiveBufferSize])); if (this.OnConnected != null) { this.OnConnected(this); } } }
protected void triggerOnReceived(ReceiveVO receiveVO, int bytesReceived) { if (this.OnReceived != null) { this.OnReceived(this, receiveVO.socket, AbstractTcpSocket.trimmedBytes(receiveVO.bytes, bytesReceived)); } }
public Socket GetClientWithRemoteEndPoint(IPEndPoint endPoint) { Socket result; this._clients.TryGetValue(AbstractTcpSocket.keyForEndPoint(endPoint), out result); return(result); }
void addClient(Socket client) { string text = AbstractTcpSocket.keyForEndPoint((IPEndPoint)client.RemoteEndPoint); this._clients.Add(text, client); this._logger.Debug("Server accepted new client connection from " + text); base.receive(new ReceiveVO(client, new byte[client.ReceiveBufferSize])); if (this.OnClientConnected != null) { this.OnClientConnected(this, client); } }
protected void send(Socket socket, byte[] buffer) { string text = AbstractTcpSocket.keyForEndPoint((IPEndPoint)socket.RemoteEndPoint); this._logger.Debug(string.Concat(new object[] { "Sending ", buffer.Length, " bytes via ", text })); socket.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(this.onSent), socket); }