DHCP vs TCP connection
What happens when I establish connection between tcpserver and tcpsocket, and computer's ip will change?
I guess that will break a connection. Am I right?
How can I protect connection from breaking in that case?
QTcpSocket will notify you when the connection is lost. You then need to reconnect.
By "disconnected" or "stateChanged" right, but what's next?
How can I tell it is connection lost apart intentional close of one program?
And what's more important, how to find new address to connect with?
QTcpSocket send a signal when there is an error or the connection state is changed. You can connect your slot to it and react there.
As for the IP: I guess it is only your client that can change the IP, right? The server's IP should remain static. So you need to reconnect from the client to the same address it used in the first place.
If that is not the case, you need to implement some other way of address discovery.
Both works in the same network, so I guess both can change IP.
How do you connect them in the first place, then? You have to have a way of finding out the IP.
In a single LAN network, you can use simple UDP broadcast messages to help peers automatically discover the server.
Or you could create a local DNS and give your server a name, but that is much harder to do.
I'm connecting them manually (entering right ip).
UDP doesn't sound like good option cuz connection need to be authorized.
This is just an UDP ping saying "I'm the server and this is my IP". Once you have it, you can connect securely using TCP like you do right now.
That is just a proven idea, anyway. Feel free to use some other approach if you want to.
Oh, didn't thought about something like this.
It actually may be a good solution.
Ducky last edited by
I all depends on how your network is setup.
There are two way's of protecting that you have the same ip.
- set your ip fix on your network controller.
- make a reservation on your DHCP server.
the difference between TCP an UDP is.
If a TCP packet fails it will be re transmitted on UDP packed it wil be not re transmitted.
Depending on your setup, use zeroconf might also be a possibility to simplify that task.