Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

The Network Chat example



  • Hello,

    I am studying the example called "Network chat", which unfortunately is not accompanied by great explanations or even comments.

    It uses a UDP socket to send a broadcast and find peers on the network. It then creates a TCP client connection to each recognized peer and a server TCP connection to receive connections from the others.
    At least that's what I understand.

    Now I was trying to modify it to not accept more than one connection from each ip, but for some reason the client connections proliferate, just change the port and I don't understand why.

    Anyone who knows the example or sockets well, can you help me?


  • Lifetime Qt Champion

    Hi
    Im not sure what went wrong with the example, after you changed it
    but I just wanted to point to this
    https://wiki.qt.io/WIP-How_to_create_a_simple_chat_application

    Its overall a better example. and far more info.



  • This is not the same example, but it may help. Thank you!



  • @Merlino said in The Network Chat example:

    Now I was trying to modify it to not accept more than one connection from each ip, but for some reason the client connections proliferate, just change the port and I don't understand why.

    I don't know the example/code. But TCP/IP allows e.g. multiple same IP connections if one side uses a different port number. Your server will need to keep a lookup of the IP clients connected (or get it from the established connections) and reject any from a duplicate client IP address.


Log in to reply