Qt matchmaking Server - c++

I want to build a matchmaking globe server,so that players on the internet can connect to and find an opponent, every player is represented by a QTcpSocket on the server.
My question is how to make the two socket talk to each other without using the glob server as a middle man? Is that even possible?
Do I need to create a server on one of them and give the other one its address?
If yes, what about NAT can I use the host number in the TCP protocol - I don't wanna use port forwarding.
Or is there any other approach in matchmaking that I don't know about.

Related

I would like to maintain three tcp/ip client connection with in a same machine and those will be connected to one server is it possible?

I am working with one requirement. Where I need to maintain three tcp/ip clients and those need to connected to the same server.
Is it possible to Run those three clients in a same machine.?
If not possible, if I need to run those clients in a three remote machines and those need to be connected to the same server, Then how could i synchronize those clients.?
I am glad if any suggestions.Thanks in advance.
Sure, why wouldn't this be possible? Those three clients can even connect to the same remote port.
Yes surely that should not be problem. Even within a same thread you can do that.
Example here. you can create more objects of the class tcp_client_c...
Yes, it is very much possible tcp connections are identified by 4-tuples
(src ip,src port, dest. ip, dest.port)
Here if you run your clients on the same machine they all have the same source ip, so their source ports will have to be different. Then all 3 of the clients can connect to the same server listening on a single port.
These 3 connections can be distiguished because one of the 4-tuple items (The source port) is different for each.
As pointed out by #Remy The OS by default assigns unique port numbers (source ports) to the Applications, but if you specifically bind to a certain port, the onus is on you to bind it to a unique port number.

Uniquely Identify UDP Connection - Multiple Connections from same IP

I'll start by saying that currently my server identifies based on sender IP, that is the IP of the client.
Now I am programming a game server (just for practice) and this got me thinking how do I uniquely identify a client if they are on the same IP. (Two players open a connection on the same machine / same network so the outward IP is the same).
I've searched for an answer both on google and here and gamedev.net but am unable to find what I am looking for, likely because I do not know the correct terms to query for.
Any guidance on this would be appreciated, especially in regards to efficiency and best practice.
Thanks.
There is no "connection" term in all stuff related to UDP, but it is common that an application that initiates a UDP socket maintains the same source port over the time, so you could identify it by source IP-port.
There is some stuff related to maintain communication between a client inside a NAT router (in NAT-UDP the client is the first host that send a UDP datagram to another host and trigger a new connection tracking entry) and a server.
This "connection tracking" is only for allow traffic from outside to inside, making a "temporal" relationship (with a timeout), that probably will not be used anymore (only once) sometimes.
If the server doesn't use the same destination port in outcoming datagram as source port in incoming one, the router won't send the datagram to the host inside NAT.
Best regards.

C++ sockets: communication between PCs over internet

I'm writing a program on Windows using winsocks that can send messages to another computer. The client connects with the server in the other computer and begin exchanging data.
It works fine on my local network using local addresses(192.168.1.*), but I can't communicate with public addresses (216.185.45.129); not even my own. I can successfully connect to a website on port 80, but not to my laptop at home using its public IP address, regardless of what ports I use (unreserved ports).
So I did research online and the only solution that seems to work is port forwarding.
-But is there absolutely no other way to achieve this?
-How do other programs like Teamviewer connect to other computers on the network then?
-Is there an already open but typically unused port that I can use?
-At the very least, can I forward the ports on my router but not have the client do anything? Or maybe have my program forward the ports automatically.
The main problem is, that every router is using NAT to distinguish different computer in your lokal network against the WAN. He need to do this, because you got only one IP in the internet, but several devices in your home. To archive this, he uses groups of ports. That means, if you use to send maybe from port 2048 to a webserver in internet with two devices, the router gives one device another port (like 2049). The response has the Port of the requester, so the router can map it back. Unfortunately most router always map ports so you never now which port you have from the internet side.
There are two common ways to work around and archive your goal.
Port Fowarding
You can force most router not to map special ports but bind them to unique MAC addresses. You can use UPNP to config most router to do that, but I do not recommend that for security reasons and also it does not work in many enviroments where Router do not allow UPNP manipulation.
Most router have port forwarding abilities for gaming reasons (mostly it is used in P2P networks)
It works with TCP and UDP.
NAT Traversal
The common way is NAT traversal, also known as NAT hole punching. I will describe it in short for UDP. You can find a wiki explanation here for TCP and for UDP here. Unfortunately you need a server in the internet both clients can reach. Here the steps:
Both clients contact the server. The server now know IP and PORT of both clients.
Server send back the information to the clients.
Both(!) clients send now packages to each other on the known address.
It is necessary that both client send a UDP package and have to accept that the first package get lost. The reason is the router. Most router only accept packages from a source on a mapped PORT if a client has send a package to that source before.
UPDATE
Regarding to a comment of Remy Lebau I changed the Firewall piercing part to NAT Traversal as it was partly wrong.

How to conect client to server through ad-hoc network by socket

I read similar posts here, but no one is really helpfull, so I ask same for Windows.
On server side we create ad-hoc network and connect to it using ad-hoc api, on client side we get enumeration of all available ad-hoc networks and connect to proper one.
Now on server side we just create listening socket, we don't need to specify any ip address.
But on client side we must know server ip address to create connection socket.
I know that socket layer is independent from higher level (ad-hoc), but it's not the answer. The goal: get ip address of server that created ad-hoc network on client that is currently connected to that network. I don't want to use other libraries like managed wi-fi.
Maybe there is some win api function to get list of ip addresses associated with ad-hoc network, some ip address range? I don't quite understand all specifics (and hardly will do, considering education process), so just point me in right direction. The language is not the matter, may it be C# or C++.
Thanks.

How to create a generic network proxy using Python or C++?

I have an application which communicates over the local area network. However, I want to instead make it communicate over the internet. To do this I propose making an intermediate program which will read the network traffic generated from the application on one computer and send it to the application on another computer.
This involves:
Reading the outgoing network traffic of the application
Sending a copy of this traffic over the internet to another computer
Giving this copy to the application on the other computer
Instead of this:
Application on computer A <-LAN-> Application on computer B
I want to achieve this:
Application on A <--> My Program on A <-INTERNET-> My program on B <--> Application on B
I can accomplish (2), but with (1) and (3) my problem is that I have very little experience with networking and I do not know where to start. I can program in python but would be willing to use c++ to accomplish this.
(Hamachi does not work for this application, I do not know why.)
In response to comments
I do not intend to manipulate any data unless it is necessary to make the connection work. I have no control over the application itself and it does not provide me with any methods to configure the connection with the exception of a port number.
TCP and UDP are both used on the port 6112. The IP addresses used are first 255.255.255.255 for a generic broadcast used to discover other applications on the LAN (with UDP), then a TCP connection is established.
The term you are missing in your original question is proxy. You specifically need a transparent forwarding proxy.
Here is a link to some source code in Python that will get you started with writing a proxy.
That said, if you search around you should be able to find a transparent forwarding proxy that you don't have to write yourself.
If you want to do this the most robust way, you can do it in hardware and setup a managed router/switch/firewall to route things to where ever you need without having to write anything.
Why re-engineer the wheel? Why not just use OpenVPN, n2n or vtun etc etc.