#include <socket.hpp>
Public Types | |
| typedef std::pair< sockaddr_in, int > | accept_t |
Public Methods | |
| int | get_sockid () |
| Get the file descriptor of the socket. | |
| socket () | |
| Default constructs a socket. | |
| socket (const int _sockid) | |
| Constructs a socket from an existing file descriptor. | |
| std::string | get_remote_name () |
| void | reuse_sock_addr () |
| Frees the port number associated with the current socket, so that on exit, the port can be re-used immediately. | |
| void | bind (unsigned short int _pno) |
| Binds a socket to a port. | |
| void | connect (unsigned short int _pno, std::string const &host_name) |
| Connects the socket to some remote host specified in the second parameter. | |
| void | listen (int max_queued=10) |
| Makes the socket listen for connections. | |
| accept_t | accept () |
| Accepts new connections if the listen() function succeeded. | |
| int | send (const char *buff, int buff_len) |
| This function sends data to the entity on the other side of the socket. | |
| int | send (std::string const &data) |
| This function sends a string to the entity on the other side of the socket. | |
| int | sendto (const char *buff, int len, std::string const &host_name) |
| This function sends data to the entity on the other side of the socket. It works on unconnected sockets. | |
| int | sendto (std::string const &msg, std::string const &host_name) |
| This function sends a string to the entity on the other side of the socket. It works on unconnected sockets. | |
| int | receive (void *buff, int buff_size) |
| A blocking function which reads data off the socket. It waits until the person at the other side has written something onto the socket, and reads off that written data. | |
| int | receive_from (void *buff, int buff_size) |
| A blocking function which reads data off the socket. It waits until the person at the other side has written something onto the socket, and reads off that written data. This function works on unconected sockets. | |
| void | close () |
| Closes the socket for reading as well as writing. | |
Static Public Methods | |
| sockaddr_in | get_socket_info (unsigned short int port_no) |
| Get the socket information. | |
| hostent * | host_by_name (std::string const &host_name) |
| Returns the host info given the host name as a string. | |
| std::string | str_ip (unsigned int uint_ip) |
| Returns the IP address as a string given the IP address in host byte order. | |
|
|
This is the type returned by the accept function. It contains: 1. The socket information such as the the IP address, etc... of the connector. 2. The file descriptor of the socket. |
|
|
Default constructs a socket. This basically creates a new socket, and assigned the new file descriptor of the socket to the internal member sock_id. |
|
|
Constructs a socket from an existing file descriptor. Checks internally in debug mode if the file descriptor is not an invalid value.
|
|
|
Accepts new connections if the listen() function succeeded.
|
|
|
Binds a socket to a port.
|
|
|
Closes the socket for reading as well as writing.
|
|
||||||||||||
|
Connects the socket to some remote host specified in the second parameter.
|
|
|
|
|
|
Get the socket information.
|
|
|
Get the file descriptor of the socket.
|
|
|
Returns the host info given the host name as a string.
|
|
|
Makes the socket listen for connections.
|
|
||||||||||||
|
A blocking function which reads data off the socket. It waits until the person at the other side has written something onto the socket, and reads off that written data.
|
|
||||||||||||
|
A blocking function which reads data off the socket. It waits until the person at the other side has written something onto the socket, and reads off that written data. This function works on unconected sockets.
|
|
|
Frees the port number associated with the current socket, so that on exit, the port can be re-used immediately.
|
|
|
This function sends a string to the entity on the other side of the socket.
|
|
||||||||||||
|
This function sends data to the entity on the other side of the socket.
|
|
||||||||||||
|
This function sends a string to the entity on the other side of the socket. It works on unconnected sockets.
|
|
||||||||||||||||
|
This function sends data to the entity on the other side of the socket. It works on unconnected sockets.
|
|
|
Returns the IP address as a string given the IP address in host byte order.
|
1.2.18