コード例 #1
0
ファイル: Communicate.cs プロジェクト: 741645596/Golf
 /// <summary>
 /// 断开连接
 /// </summary>
 public static void Disconnect()
 {
     NetConnectState.ClearMsg();
     if (gsConnector.IsConnected())
     {
         gsConnector.DisconnectFromServer();
     }
 }
コード例 #2
0
ファイル: NetConnect.cs プロジェクト: 741645596/Golf
        public void SendRawPkt(NetBuffer nb)
        {
            //非法判断
            if (mSocket == null)
            {
                IGGDebug.Log("socket is invalid.");
                return;
            }

            // 如果根本就没有连接,那么不用发送了
            if (!this.IsConnected)
            {
                return;
            }


            // 当前还有没发出去的包,为了保证顺序,我们这次也别尝试了,直接插入到Pending列表中
            if (mPendingSendPkt.Count > 0)
            {
                mPendingSendPkt.Add(nb);
            }
            // 尝试发送一次
            else
            {
                // 尝试发送这个数据包
                try
                {
                    int sentBytes = mSocket.Send(nb.Pbuffer, nb.HaveSendBytes, nb.NeedSendBuffSize, SocketFlags.None);

                    // 如果没有完整地把包发送出去
                    if (sentBytes < nb.NeedSendBuffSize)
                    {
                        NetConnectState.SendDataState(false);
                    }
                    else
                    {
                        NetConnectState.SendDataState(true);
                    }
                    nb.CGNetBuffer();
                }
                catch (Exception e)
                {
                    IGGDebug.LogError(e);
                }
            }
        }
コード例 #3
0
ファイル: NetResponsorImpl.cs プロジェクト: 741645596/Golf
        private void ProcessPacket(byte[] message, int length)
        {
            //byte[] data = new byte[length - 2];
            //Array.Copy(message, 2, data, 0, length - 2);

            //大小端转换
            ushort cmd = (ushort)message[0];

            cmd += (ushort)(message[1] << 8);

            eMsgTypes Type = (eMsgTypes)cmd;
            //IGGDebug.Log("Revice:" + Type);
            bool result = MsgM.Dispatch(Type, message, 6, length - 6);

            if (result == true)
            {
                NetConnectState.MsgArrival(cmd);
            }
        }
コード例 #4
0
ファイル: NetResponsorImpl.cs プロジェクト: 741645596/Golf
 /// <summary>
 /// 掉线的处理
 /// </summary>
 public void OnDisconnect()
 {
     NetConnectState.OnDisconnect();
 }
コード例 #5
0
ファイル: NetResponsorImpl.cs プロジェクト: 741645596/Golf
 /// <summary>
 /// 连接失败的处理
 /// </summary>
 public void OnConnectFailure()
 {
     NetConnectState.OnConnectNotify(false);
 }
コード例 #6
0
ファイル: NetResponsorImpl.cs プロジェクト: 741645596/Golf
 /// <summary>
 /// 连接成功的处理
 /// </summary>
 public void OnConnectSuccess()
 {
     NetConnectState.OnConnectNotify(true);
 }
コード例 #7
0
ファイル: NetConnectorImpl.cs プロジェクト: 741645596/Golf
 /// <summary>
 /// 每帧需要调度,以对网络数据进行处理
 /// </summary>
 /// <param name="deltaTime">帧与帧之间的流逝时间</param>
 public void Update(float deltaTime)
 {
     // 处理消息的读取和发送
     this.connect.Poll(deltaTime);
     NetConnectState.Update(deltaTime);
 }