예제 #1
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.AddMessageEvent((ushort)protocal, null);
        Debug.LogError("Connection was closed by the server:>" + msg + " Distype:>" + dis);
    }
예제 #2
0
    /// <summary>
    /// 连接上服务器
    /// </summary>
    void OnConnect(IAsyncResult asr)
    {
        if (client.Connected)
        {
            outStream = client.GetStream();
            client.GetStream().BeginRead(byteBuffer, 0, MaxRead, new AsyncCallback(OnRead), null);
            //通知该连接成功的监听者
            NetworkManager.AddMessageEvent(Protocal.Connect, null);
        }
        else
        {
            NetworkManager.AddMessageEvent(Protocal.Disconnect, null);
            Close();
        }

        //outStream = client.GetStream();
        //client.GetStream().BeginRead(byteBuffer, 0, MaxRead, new AsyncCallback(OnRead), null);
        ////通知该连接成功的监听者
        //NetworkManager.AddMessageEvent(Protocal.Connect, null);
    }
예제 #3
0
    /// <summary>
    /// 在这进行组装bytebuffer
    /// </summary>
    /// <param name="actionCode"></param>
    /// <param name="data"></param>
    void OnReceiveMessage(ushort actionCode, byte[] data)
    {
        ByteBuffer bbf = new ByteBuffer(data);

        NetworkManager.AddMessageEvent(actionCode, bbf);
    }