473,389 Members | 1,094 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,389 software developers and data experts.

Socket communication problem

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
4 2324
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
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


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


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Lindstrom Greg - glinds | last post by:
Hello- I have a python routine (Python 2.2.3 on Windows 2000 "Professional") using a socket connection. Problem is, the backend service I'm connecting to will hang every so often and the socket...
4
by: faktujaa | last post by:
Hi, I am having some problem with callback used in socket implementation. private static void Connect(string strPrtrIPAddr, int intPrtrPort, ref Socket rsocClient) { try { // Create remote end...
2
by: tantiboh | last post by:
I'm not a new programmer, but this one's got me stymied; hopefully it's a fairly trivial problem. I'm using a socket connection to receive communication from a server. Normally, the entire message...
3
by: Ricardo Quintanilla | last post by:
i had a problem whom i do not know how to explain. i was using a TcpClient (System.Net.Sockets.TcpClient) object to send and receive data to an AS400 socket. Two months ago it started to work...
13
by: coloradowebdev | last post by:
i am working on basically a proxy server that handles requests via remoting from clients and executes transactions against a third-party server via TCP. the remoting site works like a champ. my...
1
by: Mr. Beck | last post by:
Hello, Please Help..... I have been working with some tcp/ip socket communication within a C# program recently. Basicly, I have a program (myProblemProgram) that has a socket connected to...
8
by: panko | last post by:
Hello, I can't manage with asynchronous socket communication. :( I wrote a class CSocket.cs. This class is taking care of sending strings to LED display. This display is actually communicating...
0
by: =?Utf-8?B?QWxwZXIgQUtDQVlPWg==?= | last post by:
Hello, First of all I wish you a good day. My help request is about .NET asynchrounus socket communication. I have developed Server-Client Windows Forms .NET applications in VC++ .NET v2003. I...
0
by: Mangabasi | last post by:
Howdy, I would like to use the Synthesis Toolkit for a demo. I downloaded the STK from http://ccrma.stanford.edu/software/stk/index.html. It seems very powerful and user friendly. There are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.