AddEvent() public static method

public static AddEvent ( int _event, ByteBuffer, data ) : void
_event int
data ByteBuffer,
return void
Esempio n. 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));
        NetworkManager.AddEvent(0, message);
    }
Esempio n. 2
0
    void OnReceivedMessage(byte[] message)
    {
        ByteBuffer buffer = new ByteBuffer(message);
        int        mainId = buffer.ReadInt();

        NetworkManager.AddEvent(mainId, buffer);
    }
Esempio n. 3
0
    private void OnReceivedMessage(MemoryStream ms)
    {
        BinaryReader binaryReader = new BinaryReader(ms);

        byte[] buf = binaryReader.ReadBytes((int)(ms.Length - ms.Position));
        NetworkManager.AddEvent(104, new LuaByteBuffer(buf));
    }
Esempio n. 4
0
    /// <summary>
    /// 丢失链接
    /// </summary>
    void OnDisconnected(DisType dis, string msg)
    {
        Close();   //关掉客户端链接
        int protocal = dis == DisType.EXCEPTION ? Protocal.EXCEPTION : Protocal.DISCONNECT;

        NetworkManager.AddEvent(protocal, null);
    }
 /// <summary>
 /// 连接上服务器
 /// </summary>
 void OnConnect(IAsyncResult asr)
 {
     Debug.Log("连上了");
     outStream = client.GetStream();
     client.GetStream().BeginRead(byteBuffer, 0, MAX_READ, new AsyncCallback(OnRead), null);
     NetworkManager.AddEvent(Protocal.Connect, new ByteBuffer());
 }
Esempio n. 6
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));

        ByteBuffer buffer = new ByteBuffer(message);
		NetworkManager.AddEvent(Protocal.Message, buffer);
    }
Esempio n. 7
0
    private void OnReceivedMessage(MemoryStream ms)
    {
        BinaryReader binaryReader = new BinaryReader(ms);

        byte[]     data  = binaryReader.ReadBytes((int)(ms.Length - ms.Position));
        ByteBuffer data2 = new ByteBuffer(data);

        NetworkManager.AddEvent(104, data2);
    }
Esempio n. 8
0
    /// <summary>
    /// 接收到消息
    /// </summary>
    /// <param name="memoryStream"></param>
    private void OnReceivedMessage(MemoryStream memoryStream)
    {
        var binaryReader = new BinaryReader(memoryStream);
        var message      = binaryReader.ReadBytes((int)(memoryStream.Length - memoryStream.Position));

        var buffer = Encoding.UTF8.GetString(message);

        NetworkManager.AddEvent(Protocal.Message, buffer);
    }
Esempio n. 9
0
    static int AddEvent(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        int        arg0 = (int)LuaScriptMgr.GetNumber(L, 1);
        ByteBuffer arg1 = LuaScriptMgr.GetNetObject <ByteBuffer>(L, 2);

        NetworkManager.AddEvent(arg0, arg1);
        return(0);
    }
Esempio n. 10
0
    /// <summary>
    /// 丢失链接
    /// </summary>
    void OnDisconnected(DisType dis, string msg)
    {
        Close();   //关掉客户端链接
        int protocal = dis == DisType.Exception ?
                       Protocal.Exception : Protocal.Disconnect;

        NetworkManager.AddEvent(protocal.ToString(), new LuaByteBuffer(new byte[] { }));
        Debug.LogWarning("Connection was closed by the server:>" + msg + " Distype:>" + dis);
    }
Esempio n. 11
0
    /// <summary>
    /// 接收到消息
    /// </summary>
    /// <param name="ms"></param>
    void OnReceivedMessage(MemoryStream ms)
    {
        byte[] message = ms.ToArray();
        //int msglen = message.Length;
        ByteBuffer buffer = new ByteBuffer(message);

        NetworkManager.AddEvent(Protocal.Message, buffer);
        ms.Close();
    }
Esempio n. 12
0
    /// <summary>
    /// 丢失链接
    /// </summary>
    void OnDisconnected(Protocal protocal, short error, string msg)
    {
        Close();
        ByteBuffer buffer = new ByteBuffer();

        buffer.WriteShort(error);
        buffer.WriteString(msg);
        NetworkManager.AddEvent((int)protocal, new ByteBuffer(buffer.ToBytes()));
        buffer.Close();
    }
Esempio n. 13
0
 /// <summary>
 /// 丢失链接
 /// </summary>
 void OnDisconnected(string msg)
 {
     Close();   //关掉客户端链接
     if (OnEvent != null)
     {
         LuaByteBuffer buffer = new LuaByteBuffer();
         NetworkManager.AddEvent(OnEvent, Protocal.Disconnect, ref buffer);
     }
     Debug.Log("Connection was closed by the server:>" + msg);
 }
Esempio n. 14
0
 /// <summary>
 /// 连接上服务器
 /// </summary>
 void OnConnect(IAsyncResult asr)
 {
     try{
         outStream = client.GetStream();
         client.GetStream().BeginRead(byteBuffer, 0, MAX_READ, new AsyncCallback(OnRead), null);
         NetworkManager.AddEvent(Protocal.Connect, new ByteBuffer());
     } catch (Exception e) {
         Close(); Debug.LogError(e.Message);
     }
 }
Esempio n. 15
0
    /// <summary>
    /// 丢失链接
    /// </summary>
    void OnDisconnected(DisType dis, string msg)
    {
        Close();           //关掉客户端链接
        int protocol = dis == DisType.Exception ? Protocol.Exception : Protocol.Disconnect;

        ByteBuffer buffer = new ByteBuffer();

        buffer.WriteShort((short)protocol);
        NetworkManager.AddEvent(protocol, buffer);
    }
Esempio n. 16
0
    /// <summary>
    /// 丢失链接
    /// </summary>
    void OnDisconnected(DisType dis, string msg)
    {
        Close();   //关掉客户端链接
        string protocal = dis == DisType.Exception ?
                          "Exception" : "Disconnect";

        //ByteBuffer buffer = new ByteBuffer();
        //buffer.WriteShort((ushort)protocal);
        NetworkManager.AddEvent(protocal);
        Debug.LogError("Connection was closed by the server:>" + msg + " Distype:>" + dis);
    }
Esempio n. 17
0
    private 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.LogError("Connection was closed by the server:>" + msg + " Distype:>" + dis);
    }
Esempio n. 18
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));

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

        NetworkManager.AddEvent(commandId, buffer);
    }
Esempio n. 19
0
 void AddEvent(int protocal, string message)
 {
     if (_networkManagerType == 1)
     {
         NetworkManager.AddEvent(protocal, message);
     }
     else if (_networkManagerType == 2)
     {
         NetworkManager2.AddEvent(protocal, message);
     }
 }
Esempio n. 20
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);
        ushort     mainId = buffer.ReadShort();

        NetworkManager.AddEvent(mainId, buffer);
    }
Esempio n. 21
0
    /// <summary>
    /// 丢失链接
    /// </summary>
    private void OnDisconnected(DisType dis, string msg)
    {
        Close(); //关掉客户端链接
        var protocal = dis == DisType.Exception ? Protocal.Exception : Protocal.Disconnect;

        var buffer = new ByteBuffer();

        buffer.WriteInt(protocal);
        NetworkManager.AddEvent(protocal, string.Empty);
        Util.LogError("Connection was closed by the server:>" + msg + " Distype:>" + dis);
    }
Esempio n. 22
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));
        ByteBuffer buffer    = new ByteBuffer(message);
        int        mainId    = buffer.ReadShort();
        int        pbDataLen = message.Length - 2;

        byte[] pbData = buffer.ReadBytes(pbDataLen);
        NetworkManager.AddEvent(mainId, pbData);
    }
Esempio n. 23
0
    /// <summary>
    /// 接收到消息
    /// </summary>
    /// <param name="ms"></param>
    void OnReceivedMessage(int msgID, MemoryStream ms)
    {
        BinaryReader r = new BinaryReader(ms);

        byte[]        message = r.ReadBytes((int)(ms.Length - ms.Position));
        LuaByteBuffer buffer  = new LuaByteBuffer(message);

        if (OnMessage != null)
        {
            NetworkManager.AddEvent(OnMessage, msgID, ref buffer);
        }
    }
Esempio n. 24
0
    /// <summary>
    /// 连接上服务器
    /// </summary>
    void OnConnect(IAsyncResult asr)
    {
        if (!client.Connected)
        {
            OnDisconnected(DisType.Exception, "can't connect to server.");
            return;
        }

        outStream = client.GetStream();
        outStream.BeginRead(byteBuffer, 0, MAX_READ, new AsyncCallback(OnRead), null);
        NetworkManager.AddEvent(Protocal.Connect, new ByteBuffer());
    }
Esempio n. 25
0
    /// <summary>
    /// 连接上服务器
    /// </summary>
    void ConnectCallback(IAsyncResult asr)
    {
        TcpClient socket = (TcpClient)asr.AsyncState;

        if (socket.Connected == false)
        {
            NetworkManager.AddEvent(Protocol.Refused, new ByteBuffer());
            return;
        }
        outStream = client.GetStream();
        client.GetStream().BeginRead(byteBuffer, 0, MAX_READ, new AsyncCallback(OnRead), null);
        NetworkManager.AddEvent(Protocol.Connect, new ByteBuffer());
    }
Esempio n. 26
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        rid    = buffer.ReadInt();

        Debug.Log("接收到的消息rid为------>" + rid);
        NetworkManager.AddEvent(rid, buffer);
    }
Esempio n. 27
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();
        // Debug.Log(string.Format("OnReceivedMessage len {0}", message.Length));
        NetworkManager.AddEvent(Protocal.Message, buffer);
    }
Esempio n. 28
0
	private void OnDisconnected(DisType dis, string msg)
	{
		this.Close();
		int num = (dis != DisType.Exception) ? 103 : 102;
		ByteBuffer byteBuffer = new ByteBuffer();
		byteBuffer.WriteShort((ushort)num);
		NetworkManager.AddEvent(num, byteBuffer);
		Debug.LogError(string.Concat(new object[]
		{
			"Connection was closed by the server:>",
			msg,
			'Distype:>",
			dis
		}));
Esempio n. 29
0
    private void OnDisconnected(DisType dis, string msg)
    {
        this.Close();
        int @event = (dis != DisType.Exception) ? 103 : 102;

        NetworkManager.AddEvent(@event, new LuaByteBuffer(Encoding.Default.GetBytes(msg)));
        Debug.LogWarning(string.Concat(new object[]
        {
            "Connection was closed by the server:>",
            msg,
            " Distype:>",
            dis
        }));
    }
Esempio n. 30
0
 private void OnConnect(IAsyncResult asr)
 {
     if (this.client.Connected)
     {
         this.outStream = this.client.GetStream();
         this.client.GetStream().BeginRead(this.byteBuffer, 0, 8192, new AsyncCallback(this.OnRead), null);
         NetworkManager.AddEvent(101, new LuaByteBuffer(Encoding.Default.GetBytes("true")));
     }
     else
     {
         NetworkManager.AddEvent(101, new LuaByteBuffer(Encoding.Default.GetBytes("false")));
     }
     this.client.EndConnect(asr);
 }