0

I am coding a real-time, network program with UDP protocol using SFML libraries. The server will be handling all of the processing, sending packets to the client and vice versa.

I need a method to synchronize the screen updates, because there will be a real-time user interface on both sides of the network. What I am thinking is, I will have the client and server open two ports, 1 for sending the packet and the other as a sort of 'verifying' port.

Once the updates are made and verified, both loops will send a byte over the network indicating that their side is 'ready'. Once a 'ready' side receives that byte, it will know the screen is ready to update on both sides, and then render the updates.

My question is, how would I do this in C++ using SFML libraries. Is the logic correct, will I encounter network errors etc.

Comment if anything needs clearing up.

dunworray
  • 49
  • 10
  • 1
    "how would I do this in C++ using SFML libraries" - What exactly do you expect as answer? The full implementation? – Lukas May 06 '15 at 09:32
  • possible duplicate of [C++ Verifying Sent Packets on Real Time Network using SFML](http://stackoverflow.com/questions/29885488/c-verifying-sent-packets-on-real-time-network-using-sfml) – Emile Bergeron May 12 '15 at 23:19

1 Answers1

0

You should read on the subject to see how it really works, like How do the protocols of real time strategy games such as Starcraft and Age of Empires look?

There is nothing specific to know in terms of SFML as the theory is applicable to every programming languages (that uses sockets). And you've not provided the code that you're struggling with, so I can't help without Minimal, Complete, and Verifiable example.

But one thing I would say is to never wait on the network to render. This will be laggy as hell and if you want "real-time", you must simulate it without real "real-time" as there will always be latency with networking.

And if you go with UDP, you don't have a choice but to open 2 ports, one on the server and one on the client. But I would argue against using a "confirmation" port as this is useless since you'll be sending multiple times a second anyway.

See how to use sockets with SFML. I guess you already know this but it might be useful for people coming from google.

See SFML networking rts which explains way better than me what to do.

From @muhwu

Generally if you are going for a real-time game with timing critical elements, you should be placing the commands player make slightly to the future to compensate for the latency. This can be few hundred milliseconds at most.

From @sean-middleditch:

Note also that many articles are just really out of date. TCP for instance is a perfectly good choice for networking in a game like an RTS, especially with lock-step networking, and is even the protocol of choice for many smaller MMOs. Despite this, almost every article around on networking is about building a custom UDP protocol.

Speaking of gamedev.stackexchange.com, you might want to read the questions and answers, and if that does not help, then ask one there.


Asking the same question on SO might not be the way to go, as your question is too broad and as already been answered a number of times (like the first one I linked).

Emile Bergeron
  • 17,074
  • 5
  • 83
  • 129