Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / Problem with DarkGDK, Winsock and UDP

Author
Message
Master Xilo
18
Years of Service
User Offline
Joined: 8th Sep 2006
Location: Bern, Switzerland
Posted: 21st Jul 2008 16:50
(I post this here cuz it doesn't really fit in any of the other places + here are most people.)

Hi,
I want to make a simple app where I can see a black box at mousex/y. (using winsock and DGDK, positions sent with UDP)

And the boxes of all the other applications/players.

It works perfectly with 2, but lags (new positions arrive too late) with more.

I attached the project and uploaded a video that demonstrates the problem, I hope someone can help me.
VIDEO: http://www.youtube.com/watch?v=oVLTeU4fgWc

Attachments

Login to view attachments
Master Xilo
18
Years of Service
User Offline
Joined: 8th Sep 2006
Location: Bern, Switzerland
Posted: 22nd Jul 2008 01:14
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 22nd Jul 2008 03:00
Perhaps you're sending data faster than you read it, for example sending once every frame but only checking for a single message every frame (you should be reading all messages until there are no more).

Master Xilo
18
Years of Service
User Offline
Joined: 8th Sep 2006
Location: Bern, Switzerland
Posted: 23rd Jul 2008 14:23
I don't think so, or at least not in the server as the only thing the server does is handling the messages.

And even if I add:

To the client's main loop it doesn't work. What's wrong?

Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 23rd Jul 2008 14:37
I can't tell really from the videos if it is a fixed time behind or running slower.

-= Out here in the fields, I fight for my meals =-
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 23rd Jul 2008 15:39
Looks to me like you have too much data being transmitted to fast, probably flooding both the transmit and the receive buffers - when either set of buffers are full, new packets are simply discarded.

Slow the transmission down and see what happens.

Master Xilo
18
Years of Service
User Offline
Joined: 8th Sep 2006
Location: Bern, Switzerland
Posted: 23rd Jul 2008 15:54 Edited at: 23rd Jul 2008 15:54
that's impossible, I can do this with TCP without problems...
(it's just 60 times a second 10 bytes)
I must be doing something else wrong.

(EDIT: didn't test it with TCP yet, but it works with multisync, so...)

Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 23rd Jul 2008 16:57
This is like House.

It's always auto-immune.

-= Out here in the fields, I fight for my meals =-
Master Xilo
18
Years of Service
User Offline
Joined: 8th Sep 2006
Location: Bern, Switzerland
Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 23rd Jul 2008 17:06
Quote: "(it's just 60 times a second 10 bytes)
I must be doing something else wrong."


Well, that means each window is sending 60 messages a second and receiving 120, so it's actually 540 messages a second... right?

There's also the P&P on each 10 byte message that brings it up. I think it is cheaper to send one big message than ten small ones, if there is an overhead of say, 3kb to send a blank message, then "Hello" would be ~3kb, but "H" + "e" + "l" + "l" + "o" would be ~15kb.

Can't you just drop it down to 10 messages a second each and see if it changes anything?

-= Out here in the fields, I fight for my meals =-
Master Xilo
18
Years of Service
User Offline
Joined: 8th Sep 2006
Location: Bern, Switzerland
Posted: 23rd Jul 2008 17:14 Edited at: 23rd Jul 2008 17:15
Quote: "drop it down to 10 messages a second each and see if it changes anything?"


It does change, but now it doesn't look smooth anymore.
And it should be possible to send 60 per second as I CAN do this with multisync.

Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 23rd Jul 2008 17:35
They probably have different sized buffers then, or multisync doesn't have such a large over head per message.

You're going to have to code some kind of smoothing/interpolating anyway for missed messages, so might as well drop the frequency down.

It might be to do with running three on the same computer, perhaps there is a machine-wide limit on the number of messages, so you would actually only be using 1/3rd of the buffer?

-= Out here in the fields, I fight for my meals =-
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 24th Jul 2008 01:05
Quote: "And it should be possible to send 60 per second as I CAN do this with multisync"

UDP is not TCP. Apart from sending signals down a wire, they are almost nothing like each other, so what will work well with one won't with the other.

TCP will throttle the transmissions. It will stop transmission totally if the remote buffer is full. It will block your program if the local buffer is full. It will retransmit missing packets, and ensure that ordering is maintained. It will coalesce multiple transmissions on your part into larger packets and transmit fewer of them.

UDP doesn't do any of that. If the remote buffer is full, the packet will be dropped. If the local buffer if full, the packet will be dropped. If a packet is missing, it won't do anything. If the packet arrives out of order, it won't do anything. Packets will be transmitted immediately, and not coalesced, so each send will create a new packet.

Because of all that extra work the TCP driver is doing for you, the transmissions are more efficient, and the blocking makes it seem as if things are smoother. The downside is that you could lose the smoothness when you actually involve a real network (ie, a piece of wire or wireless rather than just data transfers within the network driver) where packets can be lost or delayed.

Did you know that most commercial network games transmit their packets at around 10 to 15 times per second?

For movement they generally use dead-reckoning to fill in the games, with auto-correction of the data over short spans of time (eg, interpolation says you should be at one spot but the current packet says you should be at another, so adjust the position over time to correct for the difference).

For RTS's the packets are usually based on sending timestamped commands, with the timestamp set in the immediate future, so small delays have no impact (ie, these units to attack those units, queue up the command locally for a future time, and transmit the same message with the same future time to all other clients).

Using UDP isn't just about pumping data down the wire, but doing it cleverly and with a little sleight-of-hand where needed. It's about making it look right even if things become a little out of sync - because things WILL go out of sync, as you've already seen.

Master Xilo
18
Years of Service
User Offline
Joined: 8th Sep 2006
Location: Bern, Switzerland
Posted: 24th Jul 2008 01:39
Very thanks for that!

I knew about the not correct order/not arriving and that it's faster.
I didn't know that TCP is doing so much else for me. But commercial games use UDP for movement right?
And about the interpolating:
isn't then everything 10/60 of a second too late (meaning: you are at X but they see you on -X, and the shoot a phantom -> wouldn't that look strange for you if you die when they actually wouldn't hit you?)
Or is there some technique that everyone sees everyone at the same place so for example: I tell the server that I'm on X, and he sends back that I have to be on -X now? Very complicated...

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 24th Jul 2008 16:53
Quote: "But commercial games use UDP for movement right?"

Yes, where speed is an issue. If a TCP packet is dropped, the client will wait a while, then transmit a retransmission request to the server, then wait for that packet to arrive. It's that wait and the round-trip request/retransmission that will break the timing of your game.

Quote: "isn't then everything 10/60 of a second too late"

The different between 'here' and 'there' that can occur in 1/10th of a second or so isn't much, but again, it's about making it look good, not about being 100% in sync.

Usually, all movement, collision detection, shooting etc is carried out by the server (which could be a designated client machine too). In this system it's the server that makes the decisions - the clients simply pass commands to the server (eg move forward, jump, fire, turn left) and carry out commands sent from the server (eg, reduce health, current position/rotation). Having a single authority on what state the game is in reduces the chance of inconsistencies.

Login to post a reply

Server time is: 2024-11-20 10:31:18
Your offset time is: 2024-11-20 10:31:18