Socket communication problem

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
 
S

Sagaert Johan

Check the result of the sent method to see if all bytes are sent.
perhaps you are overflowing the tcpip buffer


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
 
S

Saso Zagoranski

I have checked it...



the number of bytes send by socket.send(...) are the same as the amount
that should have been send...



about 10kB in a minute but the server receives only 30% of the data.



What do you think about this possibility?



I wrote this in the first post:

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?



saso



_____

Od: Sagaert Johan [mailto:[email protected]]
Poslano: 22. maj 2005 20:24
Objavljeno v: microsoft.public.dotnet.languages.csharp
Pogovor: Socket communication problem
Zadeva: Re: Socket communication problem


Check the result of the sent method to see if all bytes are sent.

perhaps you are overflowing the tcpip buffer






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
 
S

Saso Zagoranski

I have found the problem (not the solution :( )



One Move sends 24 bytes over the network. If the player moves very
slowly everything is ok...

but if you move very fast the Receive method receives MORE than 24 bytes
(up to 200!)...



how to get around that?



_____

Od: Saso Zagoranski [mailto:[email protected]]
Poslano: 22. maj 2005 22:47
Objavljeno v: microsoft.public.dotnet.languages.csharp
Pogovor: Socket communication problem
Zadeva: Re: Socket communication problem


I have checked it...



the number of bytes send by socket.send(...) are the same as the amount
that should have been send...



about 10kB in a minute but the server receives only 30% of the data.



What do you think about this possibility?



I wrote this in the first post:

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?



saso



_____

Od: Sagaert Johan [mailto:[email protected]]
Poslano: 22. maj 2005 20:24
Objavljeno v: microsoft.public.dotnet.languages.csharp
Pogovor: Socket communication problem
Zadeva: Re: Socket communication problem


Check the result of the sent method to see if all bytes are sent.

perhaps you are overflowing the tcpip buffer






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
 
S

Saso Zagoranski

I solved it... If I receive a lot of data in one package I just split it
in more messages.



However... since there are so many messages going over the network,
everything

still works slowly... :(



_____

Od: Saso Zagoranski [mailto:[email protected]]
Poslano: 22. maj 2005 23:21
Objavljeno v: microsoft.public.dotnet.languages.csharp
Pogovor: Socket communication problem
Zadeva: Re: Socket communication problem




I have found the problem (not the solution :( )



One Move sends 24 bytes over the network. If the player moves very
slowly everything is ok...

but if you move very fast the Receive method receives MORE than 24 bytes
(up to 200!)...



how to get around that?



_____

Od: Saso Zagoranski [mailto:[email protected]]
Poslano: 22. maj 2005 22:47
Objavljeno v: microsoft.public.dotnet.languages.csharp
Pogovor: Socket communication problem
Zadeva: Re: Socket communication problem


I have checked it...



the number of bytes send by socket.send(...) are the same as the amount
that should have been send...



about 10kB in a minute but the server receives only 30% of the data.



What do you think about this possibility?



I wrote this in the first post:

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?



saso



_____

Od: Sagaert Johan [mailto:[email protected]]
Poslano: 22. maj 2005 20:24
Objavljeno v: microsoft.public.dotnet.languages.csharp
Pogovor: Socket communication problem
Zadeva: Re: Socket communication problem


Check the result of the sent method to see if all bytes are sent.

perhaps you are overflowing the tcpip buffer






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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top