Knowledge Base Nr: 00097 chatserver.cpp - http://www.swe-kaiser.de

Downloads:

Qt: einfacher Chat-Server (QServerSocket und QSocket)

  
class CPortServerSocket : public QServerSocket
{
Q_OBJECT

public:
CPortServerSocket(CPortServer* server, int nPortNo);
~CPortServerSocket();

protected slots:
void newConnection(int socknr);
void readClient();
void writeAllClients(const char* lpszText);
void discardClient();

protected:

private:
CPortServer* m_server;

QSocket* m_socket[MAXCLIENTS];
QTextStream m_ts;
};


class CPortServer : public QVBox
{
Q_OBJECT

public:
CPortServer(int nPortNo);
~CPortServer();

void textOut(const char* lpszText);

private:
QTextView* m_infoText;
CPortServerSocket* m_serversocket;
};

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

CPortServer server(PORTNO);
app.setMainWidget(&server);
server.show();

return app.exec();
}