private void onDataReceived(object sender, DataCompleteEventArgs e) { int index = clients.IndexOf((ServerClient)sender); if (index < 0) { return; } ClientDataReceived?.Invoke(this, new ListDataCompleteEventArgs(index, e.Data)); }
internal void RaiseClientDataReceived(TcpSocketSession session, byte[] data, int dataOffset, int dataLength) { try { ClientDataReceived?.Invoke(this, new TcpClientDataReceivedEventArgs(session, data, dataOffset, dataLength)); } catch (Exception ex) { HandleUserSideError(session, ex); } }
private void ProcessReceive(SocketAsyncEventArgs e) { ClientToken clientToken = (ClientToken)e.UserToken; if (e.SocketError != SocketError.Success) { if (e.SocketError == SocketError.OperationAborted) { return; } //Fire ClientDataReceiveError event if (ClientDataReceiveError != null) { if (CallClientDataReceiveErrorAsync) { ClientDataReceiveError.BeginInvoke(this, clientToken.Id, e.SocketError, r => ClientDataReceiveError.EndInvoke(r), null); } else { ClientDataReceiveError(this, clientToken.Id, e.SocketError); } } if (!clientToken.Closed && !clientToken.Socket.DisconnectAsync(e)) { CloseClientSocket(clientToken); } return; } //Read client bytes transferred int bytesTransferred = e.BytesTransferred; if (bytesTransferred != 0) { clientToken.AcceptData(e, bytesTransferred); //Parse received data for packets List <BasePacket> packets = clientToken.ProcessReceivedDataReq(); //Fire ClientDataReceived event if (packets.Count > 0 && ClientDataReceived != null) { if (CallClientDataReceivedAsync) { ClientDataReceived.BeginInvoke(this, clientToken.Id, packets, r => ClientDataReceived.EndInvoke(r), null); } else { ClientDataReceived(this, clientToken.Id, packets); } } StartReceive(clientToken); //clientToken.AcceptDataAsync(e, bytesTransferred).ContinueWith // ( // a => // { // //Parse received data for packets // List<BasePacket> packets = clientToken.ProcessReceivedDataReq(); // //Fire ClientDataReceived event // if (packets.Count > 0 && ClientDataReceived != null) // { // ClientDataReceived.BeginInvoke(this, clientToken.Id, packets, // r => ClientDataReceived.EndInvoke(r), null); // } // StartReceive(clientToken); // } // ); return; } //Return of zero bytes transferred means that the client is no longer connected if (!clientToken.Closed && !clientToken.Socket.DisconnectAsync(e)) { CloseClientSocket(clientToken); } }
protected virtual void OnDataReceived(ClientEventArgs e) { ClientDataReceived?.Invoke(this, e); }
/// <summary> /// The client's data receive event caller /// </summary> /// <param name="e">Asynchronous event args</param> protected virtual void OnClientDataReceived(AsyncCompletedEventArgs e) { ClientDataReceived?.Invoke(this, e); }