-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathudpsocket.h
117 lines (103 loc) · 2.85 KB
/
udpsocket.h
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#ifndef UDPSOCKET_H
#define UDPSOCKET_H
#include <QObject>
#include <QDebug>
#include "socket.h"
#include <ws2tcpip.h>
/**
* Wrapper class for a Windows asynchronous UDP socket. Base socket
* functionality is provided by parent class Socket.
*
* @author Tom Nightingale
*/
class UDPSocket : public Socket
{
Q_OBJECT
private:
/** The address of the destination machine. */
SOCKADDR_IN serverSockAddrIn_;
/** Whether or not this is a multicast socket. */
bool isMulticast_;
public:
/**
* Constructor.
*
* @param hWnd The pointer to the applications mainwindow for access to the
* applications message loop.
*
* @author Tom Nightingale
*/
UDPSocket(HWND hWnd);
/**
* Destructor.
* Cleans up any resources used by the socket.
*
* @author Tom Nightingale
*/
virtual ~UDPSocket();
/**
* Reimplemented from QIODevice.
* Sets this IO device's open mode to the mode specified.
*
* @param mode The mode to set this device to.
*
* @author Tom Nightingale
*/
bool open(OpenMode mode);
/**
* Set the socket to listen for datagrams on a specific port.
*
* @param port The port to listen to for datagrams.
*
* @author Tom Nightingale
*/
virtual bool listen(int port);
/**
* Set the socket to listen for multicast datagrams on a specific port.
*
* @param address The address to listen to for multicast datagrams.
* @param port The port to listen to for multicast datagrams.
*
* @author Tom Nightingale
*/
void listenMulticast(QString address, int port);
/**
* Set the destination address of this port.
*
* @param hostAddr The address of the remote machine.
* @param param The port of the remote machine.
*
* @author Tom Nightingale.
*/
void setDest(QString hostAddr, size_t port);
public slots:
/**
* All Windows Asynchronous socket message get sent here. The message is
* parsed and then forwarded to the appropriate destination.
*
* @param socket The handle to the socket that received this message.
* @param int The actual message received.
*
* @author Tom Nightingale.
*/
void slotProcessWSAEvent(int socket, int lParam);
protected:
/**
* Manages reading from the socket into the internal socket buffer.
*
* @param pMsg The Windows message notifying the socket that there is data
* waiting to be read.
*
* @author Tom Nightingale
*/
virtual void receive(PMSG pMsg);
/**
* Manages writing data to the socket to send a connected remote machine.
*
* @param pMsg The Windows message notifying of this event.
*
* @author Tom Nightingale
*/
virtual void send(PMSG pMsg);
};
#endif // UDPSOCKET_H