void Recieve(Action<Message> callback) { try { var state = new MsgTransmitState { Callback = callback, Buffer = new byte[config.BufferSize], }; config.Connection.BeginReceive(state.Buffer, 0, config.BufferSize, SocketFlags.None, AfterReceiveMsgCallback, state); } catch (Exception e) { Logging.LogUsefulException(e); throw; } }
void Recieve(Action <Message> callback) { try { var state = new MsgTransmitState { Callback = callback, Buffer = new byte[config.BufferSize], }; config.Connection.BeginReceive(state.Buffer, 0, config.BufferSize, SocketFlags.None, AfterReceiveMsgCallback, state); } catch (Exception e) { Logging.LogUsefulException(e); throw; } }
/// <summary> /// 发送消息 /// </summary> /// <param name="msg">消息内容,通过序列化为字节流</param> /// <param name="callback"></param> public void Send(Message msg, Action<Message> callback) { var msgContent = msg.ToBytes(); try { var state = new MsgTransmitState { Message = msg, Callback = callback }; config.Connection.BeginSend(msgContent, 0, Math.Min(msgContent.Length, config.BufferSize), 0, AfterSendCallBack, state); } catch (Exception e) { Logging.LogUsefulException(e); throw; } }
/// <summary> /// 发送消息 /// </summary> /// <param name="msg">消息内容,通过序列化为字节流</param> /// <param name="callback"></param> public void Send(Message msg, Action <Message> callback) { var msgContent = msg.ToBytes(); try { var state = new MsgTransmitState { Message = msg, Callback = callback }; config.Connection.BeginSend(msgContent, 0, Math.Min(msgContent.Length, config.BufferSize), 0, AfterSendCallBack, state); } catch (Exception e) { Logging.LogUsefulException(e); throw; } }