// Update is called once per frame void Update() { if (Communicator.I().cb.GetLength() > 0) { _header[] recv = new _header[1]; Communicator.I().cb.Dequeue(recv); switch ((Protocol)recv[0].protocolID) { case Protocol.PROTOCOL_JOIN_ACK: S_PROTOCOL_JOIN_ACK[] join_ack = new S_PROTOCOL_JOIN_ACK[1]; Communicator.I().cb.Dequeue(join_ack); break; case Protocol.PROTOCOL_LOGIN_ACK: S_PROTOCOL_LOGIN_ACK[] login_ack = new S_PROTOCOL_LOGIN_ACK[1]; Communicator.I().cb.Dequeue(login_ack); if (login_ack[0].header.result == 0) { Debug.Log("SUCCESS LOGIN"); Communicator.I().setUserID(login_ack[0].userID); SceneManager.LoadScene("Main"); } break; } } }
public static void receive() { byte[] Receivebyte = new byte[2000]; // Receive data by this array to save. string ReceiveString; int ReceivedataLength; while (true) { try { m_Socket.Receive(Receivebyte); ReceiveString = Encoding.Default.GetString(Receivebyte); ReceivedataLength = Encoding.Default.GetByteCount(ReceiveString.ToString()); _header ack = new _header(); ack.Deserialize(Receivebyte); switch ((Protocol)ack.protocolID) { case Protocol.PROTOCOL_JOIN_ACK: S_PROTOCOL_JOIN_ACK join_ack = new S_PROTOCOL_JOIN_ACK(); join_ack.Deserialize(Receivebyte); Communicator.I().cb.Enqueue(ack); Communicator.I().cb.Enqueue(join_ack); break; case Protocol.PROTOCOL_LOGIN_ACK: S_PROTOCOL_LOGIN_ACK login_ack = new S_PROTOCOL_LOGIN_ACK(); login_ack.Deserialize(Receivebyte); Communicator.I().cb.Enqueue(ack); Communicator.I().cb.Enqueue(login_ack); break; } } catch (SocketException err) { Debug.Log("Socket send or receive error! : " + err.ToString()); } } }