コード例 #1
0
        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");
            }
        }
コード例 #2
0
        /// <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)
                {
                }
            }
        }
コード例 #3
0
        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");
            }
        }
コード例 #4
0
 protected void OnDataReceived(SocketDataReceived arg)
 {
     DataReceived?.Invoke(this, arg);
 }