Home > Back-end >  QT client socket communication with Linux server
QT client socket communication with Linux server

Time:11-04

Encounter a problem, use qtcpsocket socket connection Linux server, the connection is not on, but the Windows command line can be connected, what reason, online, etc., be urgent!
QT connect server code:
The socket=new QTcpSocket ();
The socket - & gt; ConnectToHost (QHostAddress (" 127.0.0.1 "), 8083);

CodePudding user response:

Less 1
The socket - & gt; WaitForConnected ();

CodePudding user response:

reference 1st floor Jonix response:
1
lessThe socket - & gt; WaitForConnected ();

,,,,,, this is verified, and it is no use

CodePudding user response:

In. H:

QTcpSocket * m_tcpsocket;

In.
in the CPP
M_tcpsocket=new QTcpSocket (this);
M_tcpsocket - & gt; Abort ();
M_tcpsocket - & gt; ConnectToHost (QHostAddress: : LocalHost, 6666);//set the client port
The connect (m_tcpsocket, SIGNAL (readyRead ()),
This SLOT (readMessage ()));//used to accept data

CodePudding user response:

refer to the second floor wu three skin response:
Quote: refer to 1st floor Jonix response:
1
lessThe socket - & gt; WaitForConnected ();

,,,,,, this is verified, with no use

Do not add waitForConnected (), you can within the local area network (LAN) maybe there is a 30% chance of normal work, but in the Internet will be almost impossible to work normally,

After connectToHost () with the if (tcpSocket waitForConnected (m_loginTimeout)) {}
Is a common usage, only must not optional ~ ~ ~

CodePudding user response:

Added or not, is there any external reason ah, I'm in qt call winsock can access

CodePudding user response:

QTcpSocket as the client to use, it is very good, and stable, estimation is the rest of the code you write is not correct,

CodePudding user response:

refer to 6th floor Jonix response:
QTcpSocket as the client to use, is very good, and stable, the estimate is the rest of the code you write is not correct,

Didn't write any code, just the few lines,,,

CodePudding user response:

Linux under the Telnet server can connect Qt, under Windows Telnet can connect under Linux server, but not on Qt client Linux server,,,, Qt client code:
QTcpsocket * socket;
The socket=new QTcpSocket ();
The socket - & gt; Abort ();
The socket - & gt; ConnectToHost (QHostAddress (" xx, XXX. XXX. Xx ""), 8083);
If (socket - & gt; WaitForConnected (3000))
{
Print success
}
The else {
Printing failed
}

CodePudding user response:

Don't worry about the size of the port 8083 end to?

CodePudding user response:

Would not Qt, direct call winsock even
  • Related