sources/network/udpsocket.h

changeset 6
c709bb1a08e4
parent 5
146825d63b9a
child 8
8b697d30c49f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sources/network/udpsocket.h	Thu Dec 11 05:59:43 2014 +0200
@@ -0,0 +1,31 @@
+#pragma once
+#include "../main.h"
+#include "ipaddress.h"
+#include "bytestream.h"
+
+enum { MAX_DATAGRAM_LENGTH = 5120 };
+
+struct Datagram
+{
+	Bytestream data;
+	IPAddress from;
+};
+
+// -------------------------------------------------------------------------------------------------
+//
+class UDPSocket
+{
+public:
+	UDPSocket();
+	virtual ~UDPSocket();
+
+	METHOD bind (unsigned short port) -> bool;
+	METHOD read (Datagram& datagram) -> bool;
+	METHOD send (const Bytestream& data, const IPAddress& addr) -> bool;
+	METHOD set_blocking (bool a) -> bool;
+
+private:
+	IPAddress m_addr;
+	String m_error;
+	int m_socket;
+};

mercurial