private void OnButton_Binary_SendMsg() { ByteStreamBuff _tmpbuff = new ByteStreamBuff(); _tmpbuff.Write_Int(1314); _tmpbuff.Write_Float(99.99f); _tmpbuff.Write_UniCodeString("Claine"); _tmpbuff.Write_UniCodeString("123456"); SocketManager.Instance.SendMsg(eProtocalCommand.sc_binary_login, _tmpbuff); }
private void CallBack_Binary_LoginServer(byte[] _msgData) { ByteStreamBuff _tmpbuff = new ByteStreamBuff(_msgData); Debug.Log(_tmpbuff.Read_Int()); Debug.Log(_tmpbuff.Read_Float()); Debug.Log(_tmpbuff.Read_UniCodeString()); Debug.Log(_tmpbuff.Read_UniCodeString()); _tmpbuff.Close(); _tmpbuff = null; }
public static void GetObjByNetData <T>(byte[] data, out NetError err, out T tData) where T : new() { ByteStreamBuff _tmpbuff = new ByteStreamBuff(data); string str = _tmpbuff.Read_String(); _tmpbuff.Close(); _tmpbuff = null; Debug.Log(str); bool isError = str.IndexOf("err") != -1; err = isError ? JsonUtility.FromJson <NetError> (str) : null; tData = isError ? new T() : JsonUtility.FromJson <T>(str); }
public void sendFromatToServer(int flag, byte dire) { ByteStreamBuff _tmpbuff = new ByteStreamBuff(); /*_tmpbuff.Write_Int(1314); * _tmpbuff.Write_Float(99.99f); * _tmpbuff.Write_UniCodeString("Claine"); * _tmpbuff.Write_UniCodeString("123456"); * SocketManager.Instance.SendMsg(eProtocalCommand.sc_binary_login, _tmpbuff);*/ switch (flag) { case MAP_FLAG: _tmpbuff.Write_Byte(MAP_FLAG); break; case JION_IN: _tmpbuff.Write_Byte(JION_IN); break; case TURN_FLAG: _tmpbuff.Write_Byte(TURN_FLAG); _tmpbuff.Write_Byte(dire); break; case GAME_STATE_FLAG: _tmpbuff.Write_Byte(GAME_STATE_FLAG); _tmpbuff.Write_Int(1); break; default: break; } SocketManager.Instance.SendMsg(_tmpbuff); return; }
/// <summary> /// 以二进制方式发送 /// </summary> /// <param name="_protocalType"></param> /// <param name="_byteStreamBuff"></param> public void SendMsg(eProtocalCommand _protocalType, ByteStreamBuff _byteStreamBuff) { SendMsgBase(_protocalType, _byteStreamBuff.ToArray()); }
/// <summary> /// 以二进制方式发送 /// </summary> /// <param name="_protocalType"></param> /// <param name="_byteStreamBuff"></param> public void SendMsg(ushort _protocalType, ByteStreamBuff _byteStreamBuff) { //SendMsgBase(_protocalType, _byteStreamBuff.ToArray()); }
public void SendMsg(ByteStreamBuff _byteStreamBuff) { SendMsgBase(_byteStreamBuff.ToArray()); }
private void gameCmd(byte[] data) { ByteStreamBuff _tmpbuff = new ByteStreamBuff(data); int flag = _tmpbuff.Read_Byte(); switch (flag) { case MAP_FLAG: int[,] tmp_game_map = new int[GAME_H, GAME_W]; List <Cooder> tmp_li_m = new List <Cooder>(); List <Cooder> tmp_li_e = new List <Cooder>(); int nodeSum; int x, y; nodeSum = _tmpbuff.Read_Int(); for (int i = 0; i < nodeSum; i++) { x = _tmpbuff.Read_Byte(); y = _tmpbuff.Read_Byte(); tmp_game_map[x, y] = SER_FLAG; if (game_sc_mode == SER_FLAG) { tmp_li_m.Add(new Cooder(x, y)); } else { tmp_li_e.Add(new Cooder(x, y)); } } nodeSum = _tmpbuff.Read_Int(); for (int i = 0; i < nodeSum; i++) { x = _tmpbuff.Read_Byte(); y = _tmpbuff.Read_Byte(); tmp_game_map[x, y] = CLI_FLAG; if (game_sc_mode == CLI_FLAG) { tmp_li_m.Add(new Cooder(x, y)); } else { tmp_li_e.Add(new Cooder(x, y)); } } food.x = _tmpbuff.Read_Byte(); food.y = _tmpbuff.Read_Byte(); game_map = tmp_game_map; snake_li_m = tmp_li_m; snake_li_e = tmp_li_e; break; case COM_DONE: game_online_flag = 1; game_sc_mode = _tmpbuff.Read_Byte(); game_move_per_ms = _tmpbuff.Read_Int(); // GAME_H = _tmpbuff.Read_Int(); // GAME_W = _tmpbuff.Read_Int(); game_map = new int[GAME_H, GAME_W]; snake_li_m = new List <Cooder>(); snake_li_e = new List <Cooder>(); food = new Cooder(0, 0); // controlMap = new int[GAME_H, GAME_W]; // for(int i=0;i<GAME_H;++i){ // for(int j=0;j<GAME_W;++j){ // controlMap[i,j]=_tmpbuff.Read_Byte(); // } // } //Debug.Log("COM_DOWN"); break; case GAME_STATE_FLAG: win_los_flag = _tmpbuff.Read_Byte(); break; case FOOD_FLAG: break; default: Debug.Log("Unknow flag!"); break; } }
/// <summary> /// 以二进制方式发送 /// </summary> /// <param name="_protocalType"></param> /// <param name="_byteStreamBuff"></param> public void SendMsg(UInt16 _protocalType, ByteStreamBuff _byteStreamBuff) { SendMsgBase(_protocalType, _byteStreamBuff.ToArray()); }