sources/network/udp.h

Thu, 11 Dec 2014 05:58:55 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Thu, 11 Dec 2014 05:58:55 +0200
changeset 5
146825d63b9a
permissions
-rw-r--r--

- code cleanup
- added network-related classes (bytestream, ipaddress, udp socket)

#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