Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, ozgur), 1,392 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19055 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
TCP question #285163
08/17/09 13:21
08/17/09 13:21
Joined: Mar 2004
Posts: 277
Zagreb
R
r00tsh3ll Offline OP
Member
r00tsh3ll  Offline OP
Member
R

Joined: Mar 2004
Posts: 277
Zagreb
Hi all,

long time no see laugh
Well dont think anyone remembers me around here anymore, anyway im around just not posting, been busy...

Onto my question laugh
Been working with UDP and stuff works as I want it to, trying to move to TCP got into "small" problem. TCP sees its connections as streams, meaning when u send 2 packets they might not arrive as 2 packets but rather as 1 combined. UDP sends packets as u construct them.

So, a bit of phyton, server side:
Code:
I:\>servertcp.py
Creating server socket...
Wait for client...
Client connected: ('192.168.248.27', 4042)
Recieved from client:  Whatever dude...
Recieved from client:  Whatever dude...
Recieved from client:  Whatever dude...Whatever dude...Whatever dude...
Recieved from client:  No more



And client:
Code:
I:\>clienttcp
Creating client socket...
Connecting to server
Connected to server, sleeping for 5 sec.
Sending message...
Sending message...
Sending message...
Sending message...
Sending message...
sending last one



So the problem is obvius (or not laugh ) the server recived packets 3,4,5 as 1 combined packet even tough client sent them separately. Or should I say they were created separately but TCP/IP stack waited, packed 3 into one and sent them as one.

Anyone know a "trick" to make TCP behave as UDP on that matter; to send packets one by one?

Re: TCP question [Re: r00tsh3ll] #285176
08/17/09 13:58
08/17/09 13:58
Joined: Nov 2002
Posts: 913
Berlin, Germany
S
SchokoKeks Offline
User
SchokoKeks  Offline
User
S

Joined: Nov 2002
Posts: 913
Berlin, Germany
you could have a look at enet:
http://enet.bespin.org/

it's open source and they have added a "layer" on top of UDP to make it act like TCP for the user, check the "features and architecture" side.
I'm afraid i can't help you any more then that, but there are some multiplayer professionals around here, just be patient and you might get a better answer.

Re: TCP question [Re: SchokoKeks] #285181
08/17/09 14:15
08/17/09 14:15
Joined: Mar 2004
Posts: 277
Zagreb
R
r00tsh3ll Offline OP
Member
r00tsh3ll  Offline OP
Member
R

Joined: Mar 2004
Posts: 277
Zagreb
Thx Schoko but i know all corners of Enet on top of my head laugh

As U said it, Enet "emulates" TCP (and does more) but is still UDP. Using it is great, still havent found a better free code on Internet than Enet. Hat down to guys that made it available to everyone.

Re: TCP question [Re: r00tsh3ll] #285185
08/17/09 14:21
08/17/09 14:21
Joined: Aug 2005
Posts: 1,230
M
MichaelGale Offline
Serious User
MichaelGale  Offline
Serious User
M

Joined: Aug 2005
Posts: 1,230
Basically the problem is very simple to solve. Normally you don't just use TCP but you add an application layer on top of it. That means you have to define your own rules for messages. For example, you could send an integer from the client to the server (always 4 bytes long) that defines the length of the string to read from the stream. Then you read the amount of bytes defined by the first integer and go over to the next message which follows the same format. Alternatively, you could use null terminated strings or whatever you like.


Your friendly mod is at your service.
Re: TCP question [Re: MichaelGale] #285190
08/17/09 14:34
08/17/09 14:34
Joined: Mar 2004
Posts: 277
Zagreb
R
r00tsh3ll Offline OP
Member
r00tsh3ll  Offline OP
Member
R

Joined: Mar 2004
Posts: 277
Zagreb
Yea, i know that too laugh
But it still doesnt send packets as they are generated, and that can generate unwanted latency. In FPS (even tough u would use UDP for that, dont want to be screwd up by TCP retransmission) this would generate unwated delay and that would be variable because u never know when will TCP send your data as 1 packet or will it sit and wait for 3 of your "send commands" and send them as 1 packet...
Another "problem" I have is with MMO game(s), clients waiting and sending 3x data in 1 packet generates unwanted overhead of delimiting/unpacking at reciver and teoreticaly if all clients wait and send 3 of generated packets in 1 TCP they generate more data to hold at once at reciver end (server) and if you have 1000 clients on a server...

Anyway just wanted to know if someone knows any trick to get rid of this TCP "feature" would be great laugh

Re: TCP question [Re: r00tsh3ll] #285198
08/17/09 14:50
08/17/09 14:50
Joined: Aug 2005
Posts: 1,230
M
MichaelGale Offline
Serious User
MichaelGale  Offline
Serious User
M

Joined: Aug 2005
Posts: 1,230
Depending on the API you use, TCP connections can be configured to send data immediately. However, this generates more data to be sent (think of the underlying protocol's headers). Also due to TCP's reliability it may take longer to send multiple data packets than to send one bigger packet after a small timeout. Like you said yourself, UDP is better suited for updating game states.

However, I do not recommend to turn off buffering because it will consume more resources.


Your friendly mod is at your service.

Moderated by  HeelX, Spirit 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1