/// <summary>
/// 发送消息给server
/// </summary>
/// <param name="datas"></param>
public void SendMessage(int msgId, byte[] datas)
{
ByteBuffer writeBuffer = null;
try
{
if (this.socket == null)
{
return;
}
writeBuffer = new ByteBuffer();
writeBuffer.WriteInt(msgId);
writeBuffer.WriteInt(datas.Length);
writeBuffer.WriteBytes(datas);
var sendBytes = writeBuffer.ToBytes();
DebugLog(identiy, "send msg id : " + msgId + " len: " + datas.Length);
writeBuffer.Close();
socket.BeginSend(sendBytes, 0, sendBytes.Length, SocketFlags.None, new AsyncCallback(this.SendMessageCallBack), socket);
}
catch (Exception e)
{
if (writeBuffer != null)
{
writeBuffer.Close();
}
DoSocketException();
DebugLogError(identiy, e.ToString());
}
}