QTcpSocket and error

  • I have a problem in my application, i think it's a problem with "arp" table or set ip address.

    I have 2 applications "Server" and "Client"

    The application "Server" before launching QTcpServer configure and Ad-hoc network and the static ip of Server =>
    The application "Client" before launching QTcpSocket configure the connexion with the ad-hoc network and its static ip is =>

    I run this application under 2 PC one app for each.
    PC A => run "Server"
    PC B => run "Client"

    First case the connection works:
    If i run A and after B, the connection is established.
    if i run B and after A, the connection is established.

    The communication work, so I close both applications.

    Second case, i switch applications
    I run PC A => "Client"
    and PC B => "Server"

    My server say the connection is established at
    If i make "ipconfig" on PC B i have

    But my client on PC A cannot join the server, the QAbstractSocketError say 'QAbstractSocket::ConnectionRefusedError' if I make "ipconfig" on PC A I have

    I have a good response of "ping" from "Client"
    I have a good response of "ping" from "Server"

    And if i tried on PC A the "Client" to connec with telnet (open port) it doesn't work.??? Why?

    If I change the ip address of "Server" to, it will working.
    In "" it's seems to be occupied or something like that.
    Someone can help me ?


  • Hi! Are your firewalls shut down? MAC (SELinux, AppArmor, Tomoyo) disabled?

  • It's not a problème with firewall because it works in first case.
    If I have used ip 192.168.0.x in first case for the server it works.
    And if i swith the client and server on pc with the same address 192.168.0.x it doesn't work.

  • Qt Champions 2017

    How do you assign these ips?

    If you are on a network with dhcp you can't use what ever
    ip you want for static.

    The correct way is to lower the range for automatically assigned ips on the dhcp router and
    then use one of none shared ips for static.
    Some routers can also do it based mac addresses.

  • Hi
    Thanks for your reply.

    There isn't dhcp because I have no router it's ad hoc network created under windows with cmd:

    Netsh wlan start hostednetwork.

    And I assign ip address with a command like that:
    Netsh interface ip set address name="Wi-Fi" static

  • Qt Champions 2017


    Ok it sounds like you know networking pretty well then.
    So if its ad hoc, it seems unlikely that the ip be in use.
    I have no further ideas it it seems u done ping test etc.

    Give it some days and see if others have better ideas.

  • Lifetime Qt Champion


    What port are you using ? Do you have anything else that might use it ?

  • The port used is 5555 but the comminucation works well.

    PC A (Server) =>
    PC B (Client) =>


    but if i swith server and client.
    PC B (Server) =>
    PC A (Client) =>

    The connection can be established.

    If i change the ip of server in this configuration
    PC B (Server) =>
    PC A (Client) =>

    it'll work ? But i don't know why.

  • Lifetime Qt Champion

    Than a silly question, did you check that the port is not still opened ?

  • How can i do that ? with listening ?

  • Lifetime Qt Champion

    netstat would likely be more appropriate

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.