Peer to Peer Connection
How to establish peer to peer connection?
From fortune examples I had learn that one App is Server that listens on some ip + port
And the second one is a client that connecting to this specific ip and this specific port.
Did I understand it right?
I need peer to peer connection.
If you have this knowledge, please, I need your help!
Why is the server client concept a problem for you?
It is also the typical setup used when peer-to-peer comms are established. Probably most of them are realized as a server-client over tcp/ip.
One correction the server is just listening. Typically it may accept any ip address and you might allow any port "see listen":http://doc.qt.nokia.com/4.7/qtcpserver.html#listen
The other side has to know the ip and may use any port then. However, you could make a scanning of possible ips to where you like to connect, if your virus scanner does allow such activity.
I need two sides (two app) with the same activity.
Like windows messaging ,but platform independent and possibility to talk to each other via network
One app sending data to the second app ,and vice versa.
So both of them should listening (like server) and connect to each other in order to send data(messages)
Is that means that both of them should be servers?
(I think it should be possible form one server connect to other server...?)
The communication is done through QTcpSocket. Those you have on both sides.
The concept of server and client is required for establishing the connection only. 99% or more will have to be identical for both, servers and clients, anyhow.
I would write one application as a server, which also, through a Gui or whatever means you like, can establish a connection as client.
Have a look to the fortune examples. After you have established the connection, try to send the information from client to server and vice versa. After the comms are established there is no difference anymore.
thank you. I'll try it
A p2p setup is nothing more than a situation where every node in a network can act as both a server and a client. No magic involved there. It depends a bit on what you are after. Is your application limited to two nodes? Do you know the address and port where you expect each of the applications to be listening?
A server is nothing more than an application that accepts incomming connections. Once a connection is established, both sides can be equal in functionality: data can flow both ways on a TCP connection. The only challenge you face, is to come up with a system to establish that first connection. I have used UPD broadcast messages for that in the past, but a better solution is of course to use something like Zeroconf for service registration and discovery.