コード例 #1
0
        /// <summary>
        /// 接收到消息
        /// </summary>
        /// <param name="ms"></param>
        void OnReceivedMessage(MemoryStream ms)
        {
            BinaryReader r = new BinaryReader(ms);

            byte[] message = r.ReadBytes((int)(ms.Length - ms.Position));
            //int msglen = message.Length;

            ByteBuffer buffer = new ByteBuffer(message);
            int        mainId = buffer.ReadShort();

            NetWorkManager.AddEvent(mainId, buffer);
        }
コード例 #2
0
        /// <summary>
        /// 丢失链接
        /// </summary>
        void OnDisconnected(DisType dis, string msg)
        {
            Close();   //关掉客户端链接
            int protocal = dis == DisType.Exception ?
                           Protocal.Exception : Protocal.Disconnect;

            ByteBuffer buffer = new ByteBuffer();

            buffer.WriteShort((ushort)protocal);
            NetWorkManager.AddEvent(protocal, buffer);
            Debug.LogWarning("Connection was closed by the server:>" + msg + " Distype:>" + dis);
        }
コード例 #3
0
 /// <summary>
 /// 连接上服务器
 /// </summary>
 void OnConnect(IAsyncResult asr)
 {
     outStream = client.GetStream();
     client.GetStream().BeginRead(byteBuffer, 0, MAX_READ, new AsyncCallback(OnRead), null);
     NetWorkManager.AddEvent(Protocal.Connect, new ByteBuffer());
 }