//接收数据 protected void AsynRecive() { try { //开始接收数据 //该步骤只读取长度 clear_receive_buffers(CommandCollection.SOCK_CONTEXT_LENGTH); _socket.BeginReceive(receive_buffers, 0, receive_buffers.Length, SocketFlags.None, readMessageLength => { _socket.EndReceive(readMessageLength); msg_length = readUShort(); clear_receive_buffers(msg_length); _socket.BeginReceive(receive_buffers, 0, receive_buffers.Length, SocketFlags.None, receiveMessage => { _socket.EndReceive(receiveMessage); ///---------读取数据 SASocketDataDAO sdd = new SASocketDataDAO(readUShort(), readBytes(msg_length - CommandCollection.SOCK_TYPE_LENGTH)); //CommandCollection.getDataModel((ProtoTypeEnum)sdd.type, sdd.bytes); SAUtils.Log("收到消息号 : " + (ProtoTypeEnum)sdd.type); dispatchEvent(Command + (ProtoTypeEnum)sdd.type, sdd); AsynRecive(); }, null); }, null); } catch (Exception ex) { SAUtils.LogError("异常信息:" + ex.Message); AsynRecive(); } }
private void errorHandler(SAFactoryEvent e) { SASocketDataDAO sdd = (SASocketDataDAO)e.Body; SError.Builder error = (SError.Builder)CommandCollection.getDataModel(ProtoTypeEnum.SError, sdd.bytes); SAUtils.LogError("错误码 : " + error.Code); }