diff options
Diffstat (limited to 'doc/html/clientserver-example.html')
-rw-r--r-- | doc/html/clientserver-example.html | 166 |
1 files changed, 83 insertions, 83 deletions
diff --git a/doc/html/clientserver-example.html b/doc/html/clientserver-example.html index e43ac9e61..13552bf94 100644 --- a/doc/html/clientserver-example.html +++ b/doc/html/clientserver-example.html @@ -35,8 +35,8 @@ body { background: #ffffff; color: black; } <p> <p> This example shows how two programs can communicate using sockets. <p> Two simple example programs are provided, a client program and a -server program. Both use the <a href="qsocket.html">TQSocket</a> class, and the server also uses -<a href="qserversocket.html">TQServerSocket</a> class. +server program. Both use the <a href="ntqsocket.html">TQSocket</a> class, and the server also uses +<a href="ntqserversocket.html">TQServerSocket</a> class. <p> The server listens on port number 4242 and accepts incoming connections. It sends back every line it receives from the client, prepended with the line number. @@ -55,14 +55,14 @@ specified. You can send single lines to the server. ** *****************************************************************************/ -#include <<a href="qsocket-h.html">qsocket.h</a>> -#include <<a href="qserversocket-h.html">qserversocket.h</a>> -#include <<a href="qapplication-h.html">qapplication.h</a>> -#include <<a href="qvbox-h.html">qvbox.h</a>> -#include <<a href="qtextview-h.html">qtextview.h</a>> -#include <<a href="qlabel-h.html">qlabel.h</a>> -#include <<a href="qpushbutton-h.html">qpushbutton.h</a>> -#include <<a href="qtextstream-h.html">qtextstream.h</a>> +#include <<a href="qsocket-h.html">ntqsocket.h</a>> +#include <<a href="qserversocket-h.html">ntqserversocket.h</a>> +#include <<a href="qapplication-h.html">ntqapplication.h</a>> +#include <<a href="qvbox-h.html">ntqvbox.h</a>> +#include <<a href="qtextview-h.html">ntqtextview.h</a>> +#include <<a href="qlabel-h.html">ntqlabel.h</a>> +#include <<a href="qpushbutton-h.html">ntqpushbutton.h</a>> +#include <<a href="qtextstream-h.html">ntqtextstream.h</a>> #include <stdlib.h> @@ -72,12 +72,12 @@ specified. You can send single lines to the server. For every client that connects to the server, the server creates a new instance of this class. */ -class ClientSocket : public <a href="qsocket.html">TQSocket</a> +class ClientSocket : public <a href="ntqsocket.html">TQSocket</a> { <a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a> public: ClientSocket( int sock, TQObject *parent=0, const char *name=0 ) : - <a href="qsocket.html">TQSocket</a>( parent, name ) + <a href="ntqsocket.html">TQSocket</a>( parent, name ) { line = 0; connect( this, SIGNAL(readyRead()), @@ -92,14 +92,14 @@ public: } signals: - void logText( const <a href="qstring.html">TQString</a>& ); + void logText( const <a href="ntqstring.html">TQString</a>& ); private slots: void readClient() { - <a href="qtextstream.html">TQTextStream</a> ts( this ); + <a href="ntqtextstream.html">TQTextStream</a> ts( this ); while ( canReadLine() ) { -<a name="x787"></a> <a href="qstring.html">TQString</a> str = ts.<a href="qtextstream.html#readLine">readLine</a>(); +<a name="x787"></a> <a href="ntqstring.html">TQString</a> str = ts.<a href="ntqtextstream.html#readLine">readLine</a>(); emit logText( tr("Read: '%1'\n").arg(str) ); ts << line << ": " << str << endl; @@ -119,15 +119,15 @@ private: client that connects, it creates a new ClientSocket -- that instance is now responsible for the communication with that client. */ -class SimpleServer : public <a href="qserversocket.html">TQServerSocket</a> +class SimpleServer : public <a href="ntqserversocket.html">TQServerSocket</a> { Q_OBJECT public: - SimpleServer( <a href="qobject.html">TQObject</a>* parent=0 ) : - <a href="qserversocket.html">TQServerSocket</a>( 4242, 1, parent ) + SimpleServer( <a href="ntqobject.html">TQObject</a>* parent=0 ) : + <a href="ntqserversocket.html">TQServerSocket</a>( 4242, 1, parent ) { if ( !ok() ) { - <a href="qapplication.html#qWarning">qWarning</a>("Failed to bind to port 4242"); + <a href="ntqapplication.html#qWarning">qWarning</a>("Failed to bind to port 4242"); exit(1); } } @@ -151,7 +151,7 @@ signals: The ServerInfo class provides a small GUI for the server. It also creates the SimpleServer and as a result the server. */ -class ServerInfo : public <a href="qvbox.html">TQVBox</a> +class ServerInfo : public <a href="ntqvbox.html">TQVBox</a> { Q_OBJECT public: @@ -159,19 +159,19 @@ public: { SimpleServer *server = new SimpleServer( this ); - <a href="qstring.html">TQString</a> itext = tr( + <a href="ntqstring.html">TQString</a> itext = tr( "This is a small server example.\n" "Connect with the client now." ); - <a href="qlabel.html">TQLabel</a> *lb = new <a href="qlabel.html">TQLabel</a>( itext, this ); -<a name="x784"></a> lb-><a href="qlabel.html#setAlignment">setAlignment</a>( AlignHCenter ); - infoText = new <a href="qtextview.html">TQTextView</a>( this ); - <a href="qpushbutton.html">TQPushButton</a> *quit = new <a href="qpushbutton.html">TQPushButton</a>( tr("Quit") , this ); + <a href="ntqlabel.html">TQLabel</a> *lb = new <a href="ntqlabel.html">TQLabel</a>( itext, this ); +<a name="x784"></a> lb-><a href="ntqlabel.html#setAlignment">setAlignment</a>( AlignHCenter ); + infoText = new <a href="ntqtextview.html">TQTextView</a>( this ); + <a href="ntqpushbutton.html">TQPushButton</a> *quit = new <a href="ntqpushbutton.html">TQPushButton</a>( tr("Quit") , this ); connect( server, SIGNAL(newConnect(ClientSocket*)), SLOT(newConnect(ClientSocket*)) ); - connect( quit, SIGNAL(<a href="qbutton.html#clicked">clicked</a>()), qApp, - SLOT(<a href="qapplication.html#quit">quit</a>()) ); + connect( quit, SIGNAL(<a href="ntqbutton.html#clicked">clicked</a>()), qApp, + SLOT(<a href="ntqapplication.html#quit">quit</a>()) ); } ~ServerInfo() @@ -181,30 +181,30 @@ public: private slots: void newConnect( ClientSocket *s ) { -<a name="x786"></a> infoText-><a href="qtextedit.html#append">append</a>( tr("New connection\n") ); - connect( s, SIGNAL(logText(const <a href="qstring.html">TQString</a>&)), - infoText, SLOT(<a href="qtextedit.html#append">append</a>(const <a href="qstring.html">TQString</a>&)) ); -<a name="x785"></a> connect( s, SIGNAL(<a href="qsocket.html#connectionClosed">connectionClosed</a>()), +<a name="x786"></a> infoText-><a href="ntqtextedit.html#append">append</a>( tr("New connection\n") ); + connect( s, SIGNAL(logText(const <a href="ntqstring.html">TQString</a>&)), + infoText, SLOT(<a href="ntqtextedit.html#append">append</a>(const <a href="ntqstring.html">TQString</a>&)) ); +<a name="x785"></a> connect( s, SIGNAL(<a href="ntqsocket.html#connectionClosed">connectionClosed</a>()), SLOT(connectionClosed()) ); } void connectionClosed() { - infoText-><a href="qtextedit.html#append">append</a>( tr("Client closed connection\n") ); + infoText-><a href="ntqtextedit.html#append">append</a>( tr("Client closed connection\n") ); } private: - <a href="qtextview.html">TQTextView</a> *infoText; + <a href="ntqtextview.html">TQTextView</a> *infoText; }; int main( int argc, char** argv ) { - <a href="qapplication.html">TQApplication</a> app( argc, argv ); + <a href="ntqapplication.html">TQApplication</a> app( argc, argv ); ServerInfo info; - app.<a href="qapplication.html#setMainWidget">setMainWidget</a>( &info ); - info.<a href="qwidget.html#show">show</a>(); - return app.<a href="qapplication.html#exec">exec</a>(); + app.<a href="ntqapplication.html#setMainWidget">setMainWidget</a>( &info ); + info.<a href="ntqwidget.html#show">show</a>(); + return app.<a href="ntqapplication.html#exec">exec</a>(); } #include "server.moc" @@ -222,49 +222,49 @@ int main( int argc, char** argv ) ** *****************************************************************************/ -#include <<a href="qsocket-h.html">qsocket.h</a>> -#include <<a href="qapplication-h.html">qapplication.h</a>> -#include <<a href="qvbox-h.html">qvbox.h</a>> -#include <<a href="qhbox-h.html">qhbox.h</a>> -#include <<a href="qtextview-h.html">qtextview.h</a>> -#include <<a href="qlineedit-h.html">qlineedit.h</a>> -#include <<a href="qlabel-h.html">qlabel.h</a>> -#include <<a href="qpushbutton-h.html">qpushbutton.h</a>> -#include <<a href="qtextstream-h.html">qtextstream.h</a>> +#include <<a href="qsocket-h.html">ntqsocket.h</a>> +#include <<a href="qapplication-h.html">ntqapplication.h</a>> +#include <<a href="qvbox-h.html">ntqvbox.h</a>> +#include <<a href="qhbox-h.html">ntqhbox.h</a>> +#include <<a href="qtextview-h.html">ntqtextview.h</a>> +#include <<a href="qlineedit-h.html">ntqlineedit.h</a>> +#include <<a href="qlabel-h.html">ntqlabel.h</a>> +#include <<a href="qpushbutton-h.html">ntqpushbutton.h</a>> +#include <<a href="qtextstream-h.html">ntqtextstream.h</a>> -class Client : public <a href="qvbox.html">TQVBox</a> +class Client : public <a href="ntqvbox.html">TQVBox</a> { Q_OBJECT public: - Client( const <a href="qstring.html">TQString</a> &host, Q_UINT16 port ) + Client( const <a href="ntqstring.html">TQString</a> &host, Q_UINT16 port ) { // GUI layout - infoText = new <a href="qtextview.html">TQTextView</a>( this ); - <a href="qhbox.html">TQHBox</a> *hb = new <a href="qhbox.html">TQHBox</a>( this ); - inputText = new <a href="qlineedit.html">TQLineEdit</a>( hb ); - <a href="qpushbutton.html">TQPushButton</a> *send = new <a href="qpushbutton.html">TQPushButton</a>( tr("Send") , hb ); - <a href="qpushbutton.html">TQPushButton</a> *close = new <a href="qpushbutton.html">TQPushButton</a>( tr("Close connection") , this ); - <a href="qpushbutton.html">TQPushButton</a> *quit = new <a href="qpushbutton.html">TQPushButton</a>( tr("Quit") , this ); + infoText = new <a href="ntqtextview.html">TQTextView</a>( this ); + <a href="ntqhbox.html">TQHBox</a> *hb = new <a href="ntqhbox.html">TQHBox</a>( this ); + inputText = new <a href="ntqlineedit.html">TQLineEdit</a>( hb ); + <a href="ntqpushbutton.html">TQPushButton</a> *send = new <a href="ntqpushbutton.html">TQPushButton</a>( tr("Send") , hb ); + <a href="ntqpushbutton.html">TQPushButton</a> *close = new <a href="ntqpushbutton.html">TQPushButton</a>( tr("Close connection") , this ); + <a href="ntqpushbutton.html">TQPushButton</a> *quit = new <a href="ntqpushbutton.html">TQPushButton</a>( tr("Quit") , this ); -<a name="x792"></a> connect( send, SIGNAL(<a href="qbutton.html#clicked">clicked</a>()), SLOT(sendToServer()) ); - connect( close, SIGNAL(<a href="qbutton.html#clicked">clicked</a>()), SLOT(closeConnection()) ); - connect( quit, SIGNAL(<a href="qbutton.html#clicked">clicked</a>()), qApp, SLOT(<a href="qapplication.html#quit">quit</a>()) ); +<a name="x792"></a> connect( send, SIGNAL(<a href="ntqbutton.html#clicked">clicked</a>()), SLOT(sendToServer()) ); + connect( close, SIGNAL(<a href="ntqbutton.html#clicked">clicked</a>()), SLOT(closeConnection()) ); + connect( quit, SIGNAL(<a href="ntqbutton.html#clicked">clicked</a>()), qApp, SLOT(<a href="ntqapplication.html#quit">quit</a>()) ); // create the socket and connect various of its signals - socket = new <a href="qsocket.html">TQSocket</a>( this ); -<a name="x798"></a> connect( socket, SIGNAL(<a href="qsocket.html#connected">connected</a>()), + socket = new <a href="ntqsocket.html">TQSocket</a>( this ); +<a name="x798"></a> connect( socket, SIGNAL(<a href="ntqsocket.html#connected">connected</a>()), SLOT(socketConnected()) ); -<a name="x799"></a> connect( socket, SIGNAL(<a href="qsocket.html#connectionClosed">connectionClosed</a>()), +<a name="x799"></a> connect( socket, SIGNAL(<a href="ntqsocket.html#connectionClosed">connectionClosed</a>()), SLOT(socketConnectionClosed()) ); -<a name="x803"></a> connect( socket, SIGNAL(<a href="qsocket.html#readyRead">readyRead</a>()), +<a name="x803"></a> connect( socket, SIGNAL(<a href="ntqsocket.html#readyRead">readyRead</a>()), SLOT(socketReadyRead()) ); -<a name="x801"></a> connect( socket, SIGNAL(<a href="qsocket.html#error">error</a>(int)), +<a name="x801"></a> connect( socket, SIGNAL(<a href="ntqsocket.html#error">error</a>(int)), SLOT(socketError(int)) ); // connect to the server -<a name="x805"></a> infoText-><a href="qtextedit.html#append">append</a>( tr("Trying to connect to the server\n") ); -<a name="x797"></a> socket-><a href="qsocket.html#connectToHost">connectToHost</a>( host, port ); +<a name="x805"></a> infoText-><a href="ntqtextedit.html#append">append</a>( tr("Trying to connect to the server\n") ); +<a name="x797"></a> socket-><a href="ntqsocket.html#connectToHost">connectToHost</a>( host, port ); } ~Client() @@ -274,10 +274,10 @@ public: private slots: void closeConnection() { -<a name="x796"></a> socket-><a href="qsocket.html#close">close</a>(); -<a name="x804"></a> if ( socket-><a href="qsocket.html#state">state</a>() == TQSocket::Closing ) { +<a name="x796"></a> socket-><a href="ntqsocket.html#close">close</a>(); +<a name="x804"></a> if ( socket-><a href="ntqsocket.html#state">state</a>() == TQSocket::Closing ) { // We have a delayed close. -<a name="x800"></a> connect( socket, SIGNAL(<a href="qsocket.html#delayedCloseFinished">delayedCloseFinished</a>()), +<a name="x800"></a> connect( socket, SIGNAL(<a href="ntqsocket.html#delayedCloseFinished">delayedCloseFinished</a>()), SLOT(socketClosed()) ); } else { // The socket is closed. @@ -288,53 +288,53 @@ private slots: void sendToServer() { // write to the server - <a href="qtextstream.html">TQTextStream</a> os(socket); -<a name="x794"></a> os << inputText-><a href="qlineedit.html#text">text</a>() << "\n"; -<a name="x793"></a> inputText-><a href="qlineedit.html#setText">setText</a>( "" ); + <a href="ntqtextstream.html">TQTextStream</a> os(socket); +<a name="x794"></a> os << inputText-><a href="ntqlineedit.html#text">text</a>() << "\n"; +<a name="x793"></a> inputText-><a href="ntqlineedit.html#setText">setText</a>( "" ); } void socketReadyRead() { // read from the server -<a name="x795"></a> while ( socket-><a href="qsocket.html#canReadLine">canReadLine</a>() ) { -<a name="x802"></a> infoText-><a href="qtextedit.html#append">append</a>( socket-><a href="qsocket.html#readLine">readLine</a>() ); +<a name="x795"></a> while ( socket-><a href="ntqsocket.html#canReadLine">canReadLine</a>() ) { +<a name="x802"></a> infoText-><a href="ntqtextedit.html#append">append</a>( socket-><a href="ntqsocket.html#readLine">readLine</a>() ); } } void socketConnected() { - infoText-><a href="qtextedit.html#append">append</a>( tr("Connected to server\n") ); + infoText-><a href="ntqtextedit.html#append">append</a>( tr("Connected to server\n") ); } void socketConnectionClosed() { - infoText-><a href="qtextedit.html#append">append</a>( tr("Connection closed by the server\n") ); + infoText-><a href="ntqtextedit.html#append">append</a>( tr("Connection closed by the server\n") ); } void socketClosed() { - infoText-><a href="qtextedit.html#append">append</a>( tr("Connection closed\n") ); + infoText-><a href="ntqtextedit.html#append">append</a>( tr("Connection closed\n") ); } void socketError( int e ) { - infoText-><a href="qtextedit.html#append">append</a>( tr("Error number %1 occurred\n").arg(e) ); + infoText-><a href="ntqtextedit.html#append">append</a>( tr("Error number %1 occurred\n").arg(e) ); } private: - <a href="qsocket.html">TQSocket</a> *socket; - <a href="qtextview.html">TQTextView</a> *infoText; - <a href="qlineedit.html">TQLineEdit</a> *inputText; + <a href="ntqsocket.html">TQSocket</a> *socket; + <a href="ntqtextview.html">TQTextView</a> *infoText; + <a href="ntqlineedit.html">TQLineEdit</a> *inputText; }; int main( int argc, char** argv ) { - <a href="qapplication.html">TQApplication</a> app( argc, argv ); + <a href="ntqapplication.html">TQApplication</a> app( argc, argv ); Client client( argc<2 ? "localhost" : argv[1], 4242 ); - app.<a href="qapplication.html#setMainWidget">setMainWidget</a>( &client ); - client.<a href="qwidget.html#show">show</a>(); - return app.<a href="qapplication.html#exec">exec</a>(); + app.<a href="ntqapplication.html#setMainWidget">setMainWidget</a>( &client ); + client.<a href="ntqwidget.html#show">show</a>(); + return app.<a href="ntqapplication.html#exec">exec</a>(); } #include "client.moc" |