Hi, I'm working on a client-server game app involving asyncronous recieving and syncronous sending. Every time a key state changes, the client is to send a state frame to the server. The problem is...after exactly 96 sends to the server, both the client and server crash! I stepped through and found that it indeed freezes on the Send() call. What could be causing this?! Here's the sending code on the client end:
{
if (m_Sock == null)
return;
switch (e.KeyCode)
{
case Keys.Up:
CurrentStateFrame.m_Accel += 0.1f;
break;
case Keys.Down:
CurrentStateFrame.m_Accel -= 0.1f;
break;
case Keys.Left:
CurrentStateFrame.m_Turning -= 0.1f;
break;
case Keys.Right:
CurrentStateFrame.m_Turning += 0.1f;
break;
}
// memory stream to serialize into
MemoryStream ms = new MemoryStream();
// formatter (how to serialize)
BinaryFormatter bf = new BinaryFormatter();
// serialize the frame
bf.Serialize(ms, CurrentStateFrame);
//fill a temp byte buffer with the serialized frame
byte[] buff = ms.GetBuffer();
//send it...
m_Sock.Send(buff, (int)ms.Length, SocketFlags.None);
listBox1.Items.Insert(0, "Sending Key State Packet to server" + (_iSends++).ToString());
}