1// Sun, 18 Jun 2000
2// Y.Takagi
3
4#ifndef __Socket_H
5#define __Socket_H
6
7#include <iostream>
8
9#include <string>
10
11#if (!__MWERKS__)
12using namespace std;
13#else
14#define std
15#endif
16
17class Socket {
18public:
19	Socket(const char *host, int port);
20	Socket(const char *host, int port, int localPort);
21	~Socket();
22
23	bool operator !() const;
24	bool good() const;
25	bool fail() const;
26
27	void close();
28	int read(char *buffer, int size, int flags = 0);
29	int write(const char *buffer, int size, int flags = 0);
30
31	istream &getInputStream();
32	ostream &getOutputStream();
33
34	int getPort() const;
35	const char *getLastError() const;
36
37private:
38	Socket(const Socket &);
39	Socket &operator = (const Socket &);
40	void open();
41
42	string  __host;
43	int     __port;
44	int     __localPort;
45	int     __sock;
46	istream *__is;
47	ostream *__os;
48	bool    __error;
49	char    __error_msg[256];
50};
51
52inline int Socket::getPort() const
53{
54	return __port;
55}
56
57inline const char *Socket::getLastError() const
58{
59	return __error_msg;
60}
61
62#endif // __Socket_H
63