日期:2014-05-17 浏览次数:20984 次
//接收数据头
void ReceiveHeader(System.IAsyncResult ar)
{
NetBitStream stream = (NetBitStream)ar.AsyncState;
try
{
int read = stream._socket.EndReceive(ar);
if (read < 1)
{
PushPacket((ushort)MessageIdentifiers.ID.CONNECTION_LOST,"", stream._socket);
return;
}
stream.DecodeHeader();
stream._socket.BeginReceive(stream.BYTES, NetBitStream.header_length, stream.BodyLength, SocketFlags.None, new System.AsyncCallback(ReceiveBody), stream);
}
catch (System.Exception e)
{
Console.WriteLine(e.Message);//异常信息:远程主机强迫关闭了一个现有连接
Console.WriteLine("1333333333333it is here!");//////////////////////////////////////////////////////////////////////////////////////////
//异常信息:指定的参数已超出有效值的范围,参数名:size
Console.ReadKey();
PushPacket((ushort)MessageIdentifiers.ID.CONNECTION_LOST, e.Message, stream._socket);
}
}