#include <Socket.h>
Public Methods | |
| Socket () | |
| Creates an empty invalid socket, used by ServerSocket. | |
| Socket (const char *addr, UINT port, SFLAG addr_type=STYPE_IP) | |
| Creates a socket that will connect to the given remote computer. | |
| Socket (const Socket &s) | |
| Copy Constructor. | |
| Socket (SOCKET s) | |
| Creates a socket based on a winsock handle, used by ServerSocket. | |
| ~Socket (void) | |
| virtual int | connect () |
| Connects to a remote computer. | |
| virtual int | send (const char *buf, UINT len) |
| Sends the given information across the socket. | |
| virtual int | recv (char *buf, UINT len) |
| Recieves the given information from the remote computer. | |
| virtual int | close () |
| Disconnects the socket. | |
| virtual int | operator<< (const char *data) |
| This operator allows you to send a null terminated string. | |
| virtual int | operator<< (char data) |
| This operator allows you to send byte of data. | |
| virtual int | operator>> (char &c) |
| This operator allows you to recieve a byte from the socket. | |
| virtual int | operator>> (char *&data) |
| This operator allows you to recieve a pointer to bytes from the socket. | |
| virtual BOOL | isConnected () |
| Returns whether the socket is currently connected. | |
Static Public Methods | |
| char * | getLocalHost () |
| Returns the name of the local host. | |
| const char * | getLastError () |
| Returns a string representing the last error. | |
| void | reportError (const char *where, const char *desc, const char *code, BOOL winerror=TRUE) |
| Creates a fomated string that represents an error. | |
| void | initWinSock () |
| void | cleanup () |
| void | addRef () |
| void | releaseRef () |
| UINT | getRefCount () |
Protected Attributes | |
| SOCKET | sock |
| The handle to the winsock socket. | |
| char * | addr |
| The address of the remote computer. | |
| UINT | port |
| The port to connect to. | |
| SFLAG | addr_type |
| The type of address contained in addr. | |
Static Protected Attributes | |
| char | lasterror [256] = {0} |
| String representaion of the last error. | |
| UINT | ref_count = 0 |
| Counts all the references to Socket, used to calculate when to do clean-up. | |
| BOOL | winsock_init = FALSE |
| Flag specifying weather winsock has been initialized or not. | |
Socket s( "www.yahoo.com", 80, STYPE_HOSTNAME ); . . . //Do other buisness here. char buf[256]; int len = s.recv( buf, 256 ); if ( len > 0 ) cout << buf << endl; . . . //Do other buisness here. s.close();
|
|
Creates an empty invalid socket, used by ServerSocket.
|
|
||||||||||||||||
|
Creates a socket that will connect to the given remote computer.
|
|
|
Copy Constructor.
|
|
|
Creates a socket based on a winsock handle, used by ServerSocket.
|
|
|
|
|
|
|
|
|
|
|
|
Disconnects the socket.
|
|
|
Connects to a remote computer.
|
|
|
Returns a string representing the last error.
|
|
|
Returns the name of the local host. For Example: Socket s( Socket::getLocalHost(), 8080, STYPE_HOSTNAME );
|
|
|
|
|
|
|
|
|
Returns whether the socket is currently connected.
|
|
|
This operator allows you to send byte of data.
|
|
|
This operator allows you to send a null terminated string.
|
|
|
This operator allows you to recieve a pointer to bytes from the socket. When this method returns successfully data will point to a new memory location that you will have to delete.
|
|
|
This operator allows you to recieve a byte from the socket.
|
|
||||||||||||
|
Recieves the given information from the remote computer.
|
|
|
|
|
||||||||||||||||||||
|
Creates a fomated string that represents an error.
|
|
||||||||||||
|
Sends the given information across the socket.
|
|
|
The address of the remote computer.
|
|
|
The type of address contained in addr.
|
|
|
String representaion of the last error.
|
|
|
The port to connect to.
|
|
|
Counts all the references to Socket, used to calculate when to do clean-up.
|
|
|
The handle to the winsock socket.
|
|
|
Flag specifying weather winsock has been initialized or not.
|
1.2.18