By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,594 Members | 3,215 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,594 IT Pros & Developers. It's quick & easy.

Socket communication problem

P: n/a
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


Nov 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Check the result of the sent method to see if all bytes are sent.
perhaps you are overflowing the tcpip buffer
"Sačo Zagoranski" <sa*************@guest.arnes.si> wrote in message news:d6**********@planja.arnes.si...
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





Nov 17 '05 #2

P: n/a
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:RE*************@hotmail.com]
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

"Sačo Zagoranski" <sa*************@guest.arnes.si> wrote in message
news:d6**********@planja.arnes.si...

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


Nov 17 '05 #3

P: n/a


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:sa*************@guest.arnes.si]
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:RE*************@hotmail.com]
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

"Sačo Zagoranski" <sa*************@guest.arnes.si> wrote in message
news:d6**********@planja.arnes.si...

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


Nov 17 '05 #4

P: n/a


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:sa*************@guest.arnes.si]
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:sa*************@guest.arnes.si]
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:RE*************@hotmail.com]
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

"Sačo Zagoranski" <sa*************@guest.arnes.si> wrote in message
news:d6**********@planja.arnes.si...

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


Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.