void client_Event(UdpClientEvents arg1, byte[] arg2) { if (arg1 == UdpClientEvents.Recv) { RecvData(arg2); } else if (arg1 == UdpClientEvents.ConnectFail) { Console.WriteLine("连接失败"); } else if (arg1 == UdpClientEvents.ConnectTimeout) { Console.WriteLine("连接超时"); } else if (arg1 == UdpClientEvents.Connected) { client.Send("data:" + m_d.ToString()); } }
private void Client_Event(UdpClientEvents arg1, byte[] buf) { if (arg1 == UdpClientEvents.Recv) { ushort DataSize = BitConverter.ToUInt16(buf, 0); //包长度 byte command = buf[2]; //命令 ushort MsgSize = (ushort)(DataSize - 3); //消息体长度 byte[] msg_datas = new byte[MsgSize]; Buffer.BlockCopy(buf, 3, msg_datas, 0, MsgSize); tcp_handle.Handle(this, command, msg_datas); } else if (arg1 == UdpClientEvents.ConnectFail) { Debug.LogError("连接失败"); //game.DisConn(); //state = -1; } else if (arg1 == UdpClientEvents.ConnectTimeout) { Debug.LogError("连接超时"); //game.DisConn(); //state = -1; } else if (arg1 == UdpClientEvents.Connected) { kcp.state = 10;//连接成功 //state = 2; //Debug.Log("Connected"); //dis_start_time = 0; //state = 1; ////登陆 //LoginRequest model_login = new LoginRequest(); //model_login.UserName = UserName; //model_login.Password = UserName; //cs.client.Send<LoginRequest>(10, model_login); } else if (arg1 == UdpClientEvents.Close) {//挂了 Debug.Log("=====================挂了"); //game.DisConn(); //state = -1; } }