private void Send()
{
IPacketBase packet = null;
//Grab a packet to send
while (!m_outgoingQueue.TryDequeue(out packet))
{
Thread.Sleep(0);
}
//Bail out if we lost connection
if (!m_socket.Connected)
{
return;
}
//Serialize the packet into the send buffer
SerializePacket(packet);
try
{
//Send packet bytes over the wire
m_sendArgs.SetBuffer(m_sendArgs.Offset, packet.Header.SizeInBytes);
if (!m_socket.SendAsync(m_sendArgs))
{
SendCompleted(m_socket, m_sendArgs);
}
}
catch (SocketException)
{
//Client disconnect
}
catch (Exception ex)
{
Console.WriteLine("Send error! " + ex);
}
}