summaryrefslogtreecommitdiffstats
path: root/examples/network/infoprotocol/infoserver/server.h
blob: fa07b93e32262a94041f6fa4cb5cb807dfe1a397 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/****************************************************************************
**
** Copyright (C) 1992-2008 Trolltech ASA.  All rights reserved.
**
** This file is part of an example program for Qt.  This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/

#ifndef SERVER_H
#define SERVER_H

#include <qsocket.h>
#include <qserversocket.h>

#include "infodata.h"
#include "serverbase.h"

static const Q_UINT16 infoPort = 42417;


/*
  The ServerInfo class provides a small GUI for the server. It also creates the
  SimpleServer and as a result the server.
*/
class ServerInfo : public ServerInfoBase
{
    Q_OBJECT
public:
    ServerInfo( Q_UINT16 port = infoPort, QWidget *parent = 0, const char *name = 0 );

private slots:
    void newConnect();
};


class SimpleServer : public QServerSocket
{
    Q_OBJECT
public:
    SimpleServer( Q_UINT16 port = infoPort, QObject* parent = 0, const char *name = 0 );
    void newConnection( int socket );

signals:
    void newConnect();

private:
    InfoData info;
};


class ClientSocket : public QSocket
{
    Q_OBJECT
public:
    ClientSocket( int sock, InfoData *i, QObject *parent = 0, const char *name = 0 );

private slots:
    void readClient();
    void connectionClosed();

private:
    QString processCommand( const QString& command );
    InfoData *info;
};


#endif //SERVER_H