473,545 Members | 1,878 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Sock ets.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(byt e[]) method.

A typical server loop looks like this:

while (true)

{

socket.Receive( buffer);

Message m = DecodeMessage(b uffer); // 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 2336
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.s i> 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.Sock ets.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(byt e[]) method.



A typical server loop looks like this:

while (true)

{

socket.Receive( buffer);

Message m = DecodeMessage(b uffer); // 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.publi c.dotnet.langua ges.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.s i> 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.Sock ets.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(byt e[]) method.

A typical server loop looks like this:

while (true)

{

socket.Receive( buffer);

Message m = DecodeMessage(b uffer); // 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.a rnes.si]
Poslano: 22. maj 2005 22:47
Objavljeno v: microsoft.publi c.dotnet.langua ges.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.publi c.dotnet.langua ges.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.s i> 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.Sock ets.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(byt e[]) method.

A typical server loop looks like this:

while (true)

{

socket.Receive( buffer);

Message m = DecodeMessage(b uffer); // 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.a rnes.si]
Poslano: 22. maj 2005 23:21
Objavljeno v: microsoft.publi c.dotnet.langua ges.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.a rnes.si]
Poslano: 22. maj 2005 22:47
Objavljeno v: microsoft.publi c.dotnet.langua ges.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.publi c.dotnet.langua ges.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.s i> 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.Sock ets.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(byt e[]) method.

A typical server loop looks like this:

while (true)

{

socket.Receive( buffer);

Message m = DecodeMessage(b uffer); // 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
1820
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 will simply wait for a response which will never come. I'm thinking of putting in a routine to check the socket's status, which now brings in...
4
2256
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 point. System.Net.IPAddress IPAddress = System.Net.IPAddress.Parse(strPrtrIPAddr); System.Net.IPEndPoint IPEndPoint = new...
2
4746
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 is received before the program moves on with its next instructions. However, at times when the processor is particularly busy the program seems to...
3
28620
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 slowly, about 4 seconds between send and receive. In our production environment with hundreds of transactions it was truly costly. a while ago i...
13
2632
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 problem is executing the transactions against the remote server and returning the response to the remoting client. i can open the socket fine and,...
1
17533
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 another program for information passing. Upon receiving a particular "command" from the the information passing program, myProblemProgram will...
8
4559
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 via serial port and serial/ethernet converter (MOXA NE-4100T) with TCP server. So communication is in that way: MyApplication(TCP...
0
2581
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 have several problems re-establishin connection between peers. Below are my problem cases after closing of the first successfull communication; ...
0
1759
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 bindings for socket connections and TCL gui examples. I would like to get one of the demo samples work with Python/wxPython. I am including the TCL...
0
7486
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7676
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7442
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5347
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4965
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3473
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3456
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1905
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
729
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.