[Interest] QTcpServer. Connecting.Sending data.

2013-10-09 Thread Alexander Syvak
Hello,

here's the code of the redefined method run() of QThread class =
void run() override

{

srv = new (std::nothrow) tcp_server(ised_win_raw_ptr);

#ifdef DEBUG

qDebug()  listener's thread =   thread();

#endif

terminate_ = false;

while ( !terminate_ ) if ( !srv-isListening() )
srv-listen(QHostAddress::Any, port);

#ifdef DEBUG

qDebug()  Deleting the ised_tcp_server object.;

#endif

srv-close(); // Closes the server. The server will no longer
listen for incoming connections.

delete srv;

}

The program connects to 9000 port for listening.

Using the netcat command
nc -vv 127.0.0.1 9000

yields

PC_NAME [127.0.0.1] 9000 (?) open

Then I typed start and hit Enter.

The break point has been set in incomingConnection which is redefined
in the tcp_server class inheriting QTcpServer.
Debugger did not paused in the method body when netcat connected to the port.


Solutions?
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] QTcpServer. Connecting.Sending data.

2013-10-09 Thread Tony Rietwyk
Hi Alexander, 

 

QTcpServer.listen only sets up the listening - it does not wait until a new
connection arrives.   In my code, I only call listen once, then run an event
loop.  The new connections arrive in the incomingConnection slot.  

 

void MyThread::run()

{

srv = new (std::nothrow) tcp_server(ised_win_raw_ptr);

if (!connect(srv,SIGNAL(newConnection(),srv,SLOT(connection())
))  error

if (!srv-listen(QHostAddress::Any, port)) error
exec();
srv-close();
delete srv;

}

 

Of course, you can put the slot anywhere.   The slot uses
nextPendingConnection() to get the socket.  

 

Works well for me.  

 

If you cannot use QThread.exec, then use srv-waitForNewConnection in your
terminate loop.  

 

Tony

 

 

From: interest-bounces+tony=rightsoft.com...@qt-project.org
[mailto:interest-bounces+tony=rightsoft.com...@qt-project.org] On Behalf Of
Alexander Syvak
Sent: Thursday, 10 October 2013 5:11 AM
To: Qt Interest
Subject: [Interest] QTcpServer. Connecting.Sending data.

 

Hello,

here's the code of the redefined method run() of QThread class =
void run() override 

{
srv = new (std::nothrow) tcp_server(ised_win_raw_ptr);
#ifdef DEBUG
qDebug()  listener's thread =   thread();
#endif
terminate_ = false;
while ( !terminate_ ) if ( !srv-isListening() )
srv-listen(QHostAddress::Any, port);
#ifdef DEBUG
qDebug()  Deleting the ised_tcp_server object.;
#endif
srv-close(); // Closes the server. The server will no longer listen
for incoming connections.
delete srv;
}
The program connects to 9000 port for listening.


Using the netcat command
nc -vv 127.0.0.1 9000
yields
PC_NAME [127.0.0.1] 9000 (?) open


Then I typed start and hit Enter.
The break point has been set in incomingConnection which is redefined
in the tcp_server class inheriting QTcpServer. 


Debugger did not paused in the method body when netcat connected to the
port.
 
 
Solutions?

 

___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest