private void OnDataReceived(object sender, SocketDataReceived e) { try { if (_isDisposed || e.Packet == null) { return; } var packet = (Packet)e.Packet; packet.ClientReceiveTime = e.Time; if (ActionUtil.IsInternalAction(packet.Action, GSLiveType.RealTime)) { _responseHandlers.GetValue(packet.Action)?.HandlePacket(packet, packet.SendType); } else { GameService.SynchronizationContext?.Send( delegate { _responseHandlers.GetValue(packet.Action)?.HandlePacket(packet, packet.SendType); }, null); } } catch (Exception exception) { exception.LogException <RealTimeHandler>(DebugLocation.RealTime, "OnDataReceived"); } }
/// <summary> /// 接收来自socket的数据 /// </summary> /// <param name="socket">套接字</param> private void Recv(Socket socket) { while (true) { try { byte[] buffer = new byte[BufferSize]; int count = socket.Receive(buffer); SocketDataReceived?.BeginInvoke(this, new SocketDataReceivedEventArgs(socket, buffer, count), null, null); // 断开连接或异常则关闭套接字并跳出返回 if (count <= 0) { if (PortMode == EthernetPortMode.Server) { SocketList.Remove(socket); } else { IsOpen = false; } socket.Close(); break; } } catch (Exception) { } } }
private void OnDataReceived(object sender, SocketDataReceived e) { try { if (e.Packet == null) { return; } var packet = (Packet)e.Packet; if (ActionUtil.IsInternalAction(packet.Action, GSLiveType.TurnBased)) { _responseHandlers.GetValue(packet.Action)?.HandlePacket(packet); } else { GameService.SynchronizationContext?.Send( delegate { _responseHandlers.GetValue(packet.Action)?.HandlePacket(packet); }, null); } } catch (Exception exception) { exception.LogException <TurnBasedHandler>(DebugLocation.TurnBased, "OnDataReceived"); } }
protected void OnDataReceived(SocketDataReceived arg) { DataReceived?.Invoke(this, arg); }