/*接收消息 * */ public int receiveMsg() { byte[] recvBuf = new byte[4096]; short size = 0; try { if (client.Receive(recvBuf, 0, 2, 0) != 2) { return(0); } size = (short)CMsg.toInteger(recvBuf, 2); if (size > 0) { if (size > CMsg.NETWORK_MSG_SIZE) { Console.WriteLine("Message Too Large"); return(0); } if (client.Receive(recvBuf, 2, size - 2, 0) == size - 2) { System.Array.Copy(recvBuf, msgStruct.GetBuf(), size); msgStruct.Clear(); return(size); } } } catch (System.Exception ex) { Console.WriteLine(ex.Message); return(0); } return(0); }