Solved Fortune examples (client and server)
-
Hi,
Thanks for your reply. I can easily retrieve the IP address of the server. When I ping it, I receive an echo but nothing about the port number.
Is there another way to find it ? -
@Diarby said in Fortune examples (client and server):
as this one is randomly supplied on server start
Do you have no way of fixing it? if you are creating the server yourself, I don't see why you shouldn't be able to fix the port
-
@Diarby
Hi normally the port is NOT random, only ip. ? -
Hi,
I'm using the Fortune Server and his client from Qt. As I have server and client, I know all information about server.
My problem is the client will be run by anyone somewhere in the world. And the server in another machine (not mine) with a name example.com. When the client is run, it must connect to that machine and I want to configure connection by code as the client user have no idea about server. As Fortune uses QTcpSocket, the client must provide IP and port. The IP is resolved with QHostInfo. It remains to resolve the port number. From the Qt example, the server produces this value with a call to serverPort() not known before running the server. -
@Diarby
Hi the server could be listing on any port. So there is no way to know which port would be right. That is normally fixed and not varying.
Also if it runs outside in he world, it will behind a firewall and that firewall must allow the port. -
@mrjj Hi. Can I use a value of 0 ?
-
@Diarby
Hi
That is not a good port.
You could use some random one for the server app and clients would always try that.
But you might be blocked by firewalls. -
Hi
https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers
Ports are normally used pr service the server provides.
You are free to use one not taken.
BUT can u trust the users to open ports? -
@mrjj
Hi. I'd try to scan all ports (from 1 to 65535) until I found the exact one. For each, I'll try a connection.
Is this solution suitable ? -
@Diarby
well if user run some local webserver or other service it might not work but
yes it could work.You do understand that most home routers comes with most ports disabled ?
and wont allow access unless open in router.So if you deployment involves random user around the world and u try to connect to them from outside, you
might get issues. -
@mrjj
Thanks for this link. I was writing when you sent it. Please give me time to read it and I'll be back tomorrow -
Hi normally the users are running the client that connects to a known IP+port to talk
to server. It sounds like you plan to do the reverse? -
@mrjj
Hi
I just finished reading the wikipedia article. From your last post, I agree to your opinion : IP + port is known by clients.
I was disturbed by Fortune Server which changes port on every launch.
A subsidiary question, why Qt let newbies learn client/server programming with this example ? -
@Diarby said in Fortune examples (client and server):
I was disturbed by Fortune Server which changes port on every launch.
Just change
if (!tcpServer->listen())
toif (!tcpServer->listen(QHostAddress::Any,13008))
in the server then you can be 100% sure the port will be 13008A subsidiary question, why Qt let newbies learn client/server programming with this example ?
I know, it's proper garbage.
Try page 323 (341 of the PDF) of C++ GUI Programming with Qt4. It's a bit old andQDataStream
evolved and made everything easier but it's still better than the Fortune example -
@Diarby
Ok, so it will not be reversed in your case?
The Fortune examples just teach how to use the Qt classes.
Its not really up to the task of teaching basic networking. ( or not included at least)
But there are tons of info about that on net. -