Marine systems simulation
server.h
1#ifndef SERVER_H
2#define SERVER_H
3
4#include <QtNetwork>
5#include <QUdpSocket>
6#include <QHostAddress>
7#include "myOutputStruct.h"
8#include <qbytearray.h>
9
10#define LISTEN_PORT 1505
11
12
16
17
18
19class Server : public QUdpSocket
20{
21 Q_OBJECT
22
23public:
24 // Constructor
25 Server(QWidget *parent = 0)
26 {
27 udpSocket = new QUdpSocket(this);
28 udpSocket->bind(QHostAddress::LocalHost, LISTEN_PORT);
29 };
30
31
32 void initSocket()
33 {
34
35 connect(udpSocket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));
36 }
37
38
39signals:
40 void FhSimDataReceived( myOutputStruct str);
41 private slots:
42
43 void readPendingDatagrams()
44 {
45 myOutputStruct FHSimData;
46 while (udpSocket->hasPendingDatagrams()) {
47 QByteArray datagram;
48 datagram.resize(udpSocket->pendingDatagramSize());
49
50 udpSocket->readDatagram((char *)&FHSimData, sizeof(FHSimData));
51
52 emit FhSimDataReceived( FHSimData) ;
53
54 }
55
56 }
57
58private:
59 QUdpSocket* udpSocket;
60
61};
62
64
65#endif
Definition: server.h:20
Definition: myOutputStruct.h:5