Qtcpserver listening on multiple ports

  • hello,
    I am a beginner to Qt.
    basically in my application i had 5 Pc's. one will act as server and all the others acts as clients. my requirement is to connect to those 4 Client pcs to the server pc. in my code i called listen function 4 times with ifferent ports and in my client applications i took 4 different ports to connect to server pc.
    but it is not happening. please help. how to do that```

    in my server code i implemented as follows
    server-> listen(hostaddress,1232);
    server-> listen(hostaddress,1233);
    server-> listen(hostaddress,1234);
    server-> listen(hostaddress,1235);

    so i thought the server will listen to multiple clients. but it is listening on on the last line i.e on 1235 port
    please help me how to do that. thanks in advance

  • @bharathballa

    You don't need to create four different ports to connect to a server. As server can serve multiple clients at the same time, you can connect to multiple clients with same port.

  • Lifetime Qt Champion

    Hi @bharathballa,

    please have a look at the examples: http://doc.qt.io/qt-5/examples-network.html

    As already said, you only need to listen on one port.

Log in to reply