S
Sa¹o Zagoranski
Hi!
I'm writing a simple 3D First person shooter game. It is a multiplayer
game, where all the players connect
to one server.
I'm using the System.Net.Sockets.Socket class for communication over TCP
protocol (I know that good games
use UDP).
I report changes to the server through simple Messages (a messages would
look like: [messOwner, Type, ...]),
where a typical message is about 20-30 bytes in size.
So if a client moves I send a message ([client1, Move, NewPosition]) to
the server and the server then transmits
this message to the other clients in the game.
The messages is sent using the Socket.Send(byte[]) method.
A typical server loop looks like this:
while (true)
{
socket.Receive(buffer);
Message m = DecodeMessage(buffer); // I just create a message
object from the buffer here
MyMessageQueue.Enqueue(m); // the message is enqueued in a simple
message queue and is processed on another thread
}
The problem is this:
If a client is constantly moving, it is sending a Move message each
frame (about 40-60 messages on average)
and the server doesn't GET all of them! Even if there is only one player
- over a LAN network only 30% of all messages arrives (if the server and
the client
are on the same machine all the messages get there). I know this because
I've added counters on both sides .
The message queue works very well... what ever get's in there - gets
processed. Could the problem be in the Receive method?
Is it possible that, while I'm processing the message, the client sends
more than one message in that time (overwrites what was there before)
and the server just
picks up the last data received?
If so... anyway to get around that? (While still sending information
every frame if neccessary - I will changes this only as a last resort
).
thanks,
saso
I'm writing a simple 3D First person shooter game. It is a multiplayer
game, where all the players connect
to one server.
I'm using the System.Net.Sockets.Socket class for communication over TCP
protocol (I know that good games
use UDP).
I report changes to the server through simple Messages (a messages would
look like: [messOwner, Type, ...]),
where a typical message is about 20-30 bytes in size.
So if a client moves I send a message ([client1, Move, NewPosition]) to
the server and the server then transmits
this message to the other clients in the game.
The messages is sent using the Socket.Send(byte[]) method.
A typical server loop looks like this:
while (true)
{
socket.Receive(buffer);
Message m = DecodeMessage(buffer); // I just create a message
object from the buffer here
MyMessageQueue.Enqueue(m); // the message is enqueued in a simple
message queue and is processed on another thread
}
The problem is this:
If a client is constantly moving, it is sending a Move message each
frame (about 40-60 messages on average)
and the server doesn't GET all of them! Even if there is only one player
- over a LAN network only 30% of all messages arrives (if the server and
the client
are on the same machine all the messages get there). I know this because
I've added counters on both sides .
The message queue works very well... what ever get's in there - gets
processed. Could the problem be in the Receive method?
Is it possible that, while I'm processing the message, the client sends
more than one message in that time (overwrites what was there before)
and the server just
picks up the last data received?
If so... anyway to get around that? (While still sending information
every frame if neccessary - I will changes this only as a last resort

).
thanks,
saso