5 #define WIN32_LEAN_AND_MEAN
9 #pragma comment(lib, "wsock32.lib")
10 typedef SOCKET socket_t;
11 typedef int socklen_t;
13 #include <sys/socket.h>
14 #include <netinet/in.h>
22 #include "exceptions.h"
23 #include "constants.h"
25 class SocketException : public BaseException
28 SocketException(const char *s):
34 class ResolveError : public BaseException
37 ResolveError(const char *s):
43 class SendFailedException : public BaseException
46 SendFailedException(const char *s):
53 void sockets_cleanup();
59 Address(unsigned int address, unsigned short port);
60 Address(unsigned int a, unsigned int b,
61 unsigned int c, unsigned int d,
63 bool operator==(Address &address);
64 bool operator!=(Address &address);
65 void Resolve(const char *name);
66 unsigned int getAddress() const;
67 unsigned short getPort() const;
68 void setAddress(unsigned int address);
69 void setPort(unsigned short port);
70 void print(std::ostream *s) const;
73 unsigned int m_address;
74 unsigned short m_port;
82 void Bind(unsigned short port);
85 void Send(const Address & destination, const void * data, int size);
86 // Returns -1 if there is no data
87 int Receive(Address & sender, void * data, int size);
88 int GetHandle(); // For debugging purposes only
89 void setTimeoutMs(int timeout_ms);
90 // Returns true if there is data, false if timeout occurred
91 bool WaitData(int timeout_ms);