Qt server-client game, clients communicate?
-
hello,
I'm coding a simple small game. I have a server app and a client app. When started, the client app connects to server via QTcpSocket and establishes connections, it then sends login and pass that server checks in database (MySql - irrelevant for this disscusion). Till now it's all good but after the client is verified, and kinda logged in, it then receives a map ID that it's currently at and the map loads. The fun part begins now. I want all clients to "see" each other on the map (there's a small avatar like thingy that i animate while "walking" around the map).
To do so i can either:- use the TCP connections with server: client sends server info that it changed position on map, the server then sends that info to all the other clients on the same map so that the other clients app can display the change,
- using TCP would be rather slow, wouldn't it ?
- plus server would be under heavy TCP attack all the time, and would still have to redirect all the packets it gets. It could crash easily this way, right?
- use TCP to connect clients that are on the same map (same map ID) together. That would require at least a couple of sockets oppened, one for each client on the same map. It would take most of the traffic that server would have to deal with if 1), but then again it would give clients a handfull of work.
- lets say a client has oppened 10 sockets for his peers on the map and sends each of them data on his position change, would that work efficiently given i have a thread for each socket ?
-
after the TCP connection is established and all the data receive i could create a p2p network with clients on the same map (same map ID) and then they would communicate with each other, right? would that be possible in qt? if so, how can I create such a p2p network?
-
i was thinking about using VPN but i have no idea how to create a vpn server and how to handle clients in it. i know qt has some VPN libraries based on openVPN but that's all. if using VPN would be a good way to handle clients communications please do tell where can i read and learn more about it.
-
another interesting idea i had was VLAN (multicasting all the data on UDP channels), hamachi ofcourse, but for non-commercial usage it only enables up to 5 clients in the network. So is there a way to code something similar like hamachi in qt? or would that require raw C++ ?
-
i was reading about UDP punching but in this scenario i think mutlicasting is out of the question. So with low reliability of UDP this could cause some problems.
-
Here comes your idea, if you have any
I would be very gratefull for any opinions on this matter. I'm almost decided on 2) but VPN or VLAN would be highly welcomed if i knew how to handle them,
I'm not native or fluent english speaker so please forgive me for any misspellings, grammar mistakes or talking nonsense,
as we say in my country "thank you from the mountain" (thank you in advance),
regards -
How about each client sends his position to the server every 20ms (or whatever interval you prefer) and server sends a message to each client every 20ms (or whatever interval you prefer) listing the positions of all players on the map. This should not be too much traffic (unless you plan to have over I don't know 1000 player or something). The best fitting interval in which you send the positions to and from the server might need to be tuned a little by testing. This should also be somehow related to the fps rate you have (the 20ms interval would corelate roughly to a 50 fps rate). Although you don't need to have the same position update rate as you have for your frame update rate (you can interpolate and preestimate new positions depending on the the last received position updates).
-
bjanuario, I'll read up all about SOAP usage in qt, thanks.
-edit1: can't find QT server SOAP example, only libs which i'm kinda afraid of using being relatively new to QT...
-edit2: SOAP uses sth like php POST and GET methods (right?), so every client has to ask server for data which either way all clients need to send to the server... so not only server respons to every data request but also has to store all the data and receive updates... OR i suck at understanding how SOAP works hmmKA510, I'm asking for a method to send and receive those positions from each client to all other,
I understand you recomend using servers TCP connections for this, but then again:
" – using TCP would be rather slow, wouldn’t it ?
– plus server would be under heavy TCP attack all the time, and would still have to redirect all the packets it gets. It could crash easily this way, right? " -
[quote author="comanderv" date="1370852855"]
KA510, I'm asking for a method to send and receive those positions from each client to all other,
I understand you recomend using servers TCP connections for this, but then again:
" – using TCP would be rather slow, wouldn’t it ?
– plus server would be under heavy TCP attack all the time, and would still have to redirect all the packets it gets. It could crash easily this way, right? "[/quote]Sending from client to client instead of client to server does not really reduce the amount of messages being send. This way each client would have to send messages to every other client on the map. So this would in the end result in even more messages being send over the network. The client to client vs client to server approach is more of a design choice. Both have their drawbacks, it depends entirely on your requirements what you should choose. But if you are so concerned with the amount of messages being send the client server approach IMHO is better. Example:
10 clients (client to client approach) : each client has to send 9 messages (to all the other clients) and receives 9 messages from all the other clients.
Total of messages send per update 109 = 90
10 clients (client to server approach): each client sends one message to the server; the server sends 10 messages to all clients; each client receives one message.
Total of messages send per update 101 + 1*10 = 20Are you asking for a different way to send the messages (e.g. UDP instead of TCP clients) ? UDP has the drawback that it does not offer reliable transmission. So you might loose messages without noticing. If that is no problem for you UDP is going to be faster than TCP with small messages (according to "this SO thread":http://stackoverflow.com/questions/47903/udp-vs-tcp-how-much-faster-is-it).
-
KA510, you only took into consideration a situation that there is only one map. What if there are 10 maps with 10 clients each?
10 maps, 10 clients each map (client2client): every client on map sends messages to all other clients on the same map
Total of messages send as you counted: 90
10 maps, 10 cleints each map (cleint2server) server receives 100 messages (10x times 10), processess them indentifying from which map they came and sending back to clients on responding map.
total messages send: 200plus this ways server is on heavy TCP attack all the time and can crash or slow down the communication.
about UDP, yeah it works fine on LAN - tried it but without VLAN its impossible to cast it across WAN, or so i read.
i'm kinda getting settled on this TCP client2client approach but i'm not sure if i would have to forward ports to communicate hmm.
It was all fun and easy when on LAN...anyways thanks for your time
-
You should read this "http://www.kdab.com/kdab-products/kd-soap/":http://www.kdab.com/kdab-products/kd-soap/ , Digia have now a strong partnership with KDAB and I use very often and is very powerful and easy to develop under their framework .
[quote author="comanderv" date="1370852855"]bjanuario, I'll read up all about SOAP usage in qt, thanks.
-edit1: can't find QT server SOAP example, only libs which i'm kinda afraid of using being relatively new to QT...
-edit2: SOAP uses sth like php POST and GET methods (right?), so every client has to ask server for data which either way all clients need to send to the server... so not only server respons to every data request but also has to store all the data and receive updates... OR i suck at understanding how SOAP works hmmKA510, I'm asking for a method to send and receive those positions from each client to all other,
I understand you recomend using servers TCP connections for this, but then again:
" – using TCP would be rather slow, wouldn’t it ?
– plus server would be under heavy TCP attack all the time, and would still have to redirect all the packets it gets. It could crash easily this way, right? "[/quote] -
In case you're having problems with ports and or firewalls maybe "RESTful web services":http://en.wikipedia.org/wiki/Representational_state_transfer#RESTful_web_APIs could be considered. Since they are using the HTTP port 80 you will have no problems with firewalls or blocked ports. Using QNetworkManager I think you could just send simple POST requests.
[quote author="comanderv" date="1370860702"]KA510, you only took into consideration a situation that there is only one map. What if there are 10 maps with 10 clients each?
10 maps, 10 clients each map (client2client): every client on map sends messages to all other clients on the same map
Total of messages send as you counted: 90
10 maps, 10 cleints each map (cleint2server) server receives 100 messages (10x times 10), processess them indentifying from which map they came and sending back to clients on responding map.
total messages send: 200 [/quote]10 maps, 10 clients each map (client2client): each client sends 9 messages, receives 9 messages.
For 10 maps thats 900 messages in the network
10 maps, 10 clients each map (client2server): each client sends one message, receives one message. server sends 100 messages receives 100 messages.
Thats a total of 200 messages in the network. -
thank you guys very much,
i have a lot to read and reconsider,
i'm sure you'll be hearing from me soon,
as for now i have problems with mysql driver on win (i used xubuntu before...) but as soon as i'm done with it i'll start SOAPing and reading and i see i will need to use libraries outsied QT which is a new thing for me,thanks again
-
i started browsing google and stumbled upon "Bonjour":http://doc.qt.digia.com/qq/qq23-bonjour.html and it says it's advertising services without needing to know the machine's IP.
would that settle my (at least for now) imaginary problem with port forwarding? (as far as i know behind NAT all ports and IPs are very different then those seen from outside, right?).
there's also QT's fortune server/client example which i'm sure i can reuse for my needs,has anyone had any experience with this Bonjour/Zeroconf class?
this will help me a lot building a TCP/UPD p2p connections ideal for me.as to SOAP and RESTful i still see too many similarities with PHP way of doing things,
the client asks server, the server gives response - the problem is that the serve has to have the updated data ale the time ... and i only need server to verify clients login and pass, the rest i want the clients to do among each other (send them their position - for now server doesnt need to know them)
plus SOAP only has client side implementation in QT and RESTful i guess does'nt have any. I'm really set on using pure QT and QT libs... hmm