#include <ArSocket.h>
Public Methods | |
ArSocket () | |
Constructor. | |
ArSocket (const char *host, int port, Type type) | |
Constructor which connects to a server. More... | |
ArSocket (int port, bool doClose, Type type) | |
Constructor which opens a server port. More... | |
~ArSocket () | |
Destructor. | |
bool | copy (int fd, bool doclose) |
Copy socket structures. More... | |
void | copy (ArSocket *s) |
Copy socket structures. | |
void | transfer (ArSocket *s) |
Transfer ownership of a socket. More... | |
bool | connect (const char *host, int port, Type type) |
Connect as a client to a server. | |
bool | open (int port, Type type) |
Open a server port. | |
bool | create (Type type) |
Simply create a port. | |
bool | findValidPort (int startPort) |
Find a valid unused port and bind the socket to it. | |
bool | connectTo (const char *host, int port) |
Connect the socket to the given address. | |
bool | connectTo (struct sockaddr_in *sin) |
Connect the socket to the given address. | |
bool | accept (ArSocket *sock) |
Accept a new connection. | |
bool | close () |
Close the socket. | |
int | write (const void *buff, size_t len) |
Write to the socket. More... | |
int | read (void *buff, size_t len, unsigned int msWait=0) |
Read from the socket. More... | |
int | sendTo (const void *msg, int len) |
Send a message on the socket. | |
int | sendTo (const void *msg, int len, struct sockaddr_in *sin) |
Send a message on the socket. | |
int | recvFrom (void *msg, int len, sockaddr_in *sin) |
Receive a message from the socket. | |
bool | getSockName () |
Get the socket name. Stored in ArSocket::mySin. | |
sockaddr_in * | sockAddrIn () |
Accessor for the sockaddr. | |
in_addr * | inAddr () |
Accessor for the in_addr. | |
unsigned short int | inPort () |
Accessor for the port of the sockaddr. | |
bool | setLinger (int time) |
Set the linger value. | |
bool | setBroadcast () |
Set broadcast value. | |
bool | setReuseAddress () |
Set the reuse address value. | |
bool | setNonBlock () |
Set socket to nonblocking. | |
void | setDoClose (bool yesno) |
Change the doClose value. | |
int | getFD () const |
Get the file descriptor. | |
Type | getType () const |
Get the protocol type. | |
const std::string & | getErrorStr () const |
Get the last error string. | |
Error | getError () const |
Get the last error. | |
int | writeString (const char *str,...) |
Writes a string to the socket. More... | |
bool | readString (char *buf, size_t len) |
Reads a string from the socket. More... | |
Static Public Methods | |
bool | init () |
Initialize the network layer. More... | |
void | shutdown () |
Shutdown the network layer. More... | |
bool | hostAddr (const char *host, struct in_addr &addr) |
Convert a host string to an address structure. | |
bool | addrHost (struct in_addr &addr, char *host) |
Convert an address structure to a host string. | |
std::string | getHostName () |
Get the localhost address. | |
void | inToA (struct in_addr *addr, char *buff) |
Convert addr into string numerical address. | |
const size_t | sockAddrLen () |
Size of the sockaddr. | |
const size_t | maxHostNameLen () |
Max host name length. | |
unsigned int | hostToNetOrder (int i) |
Host byte order to network byte order. | |
unsigned int | netToHostOrder (int i) |
Network byte order to host byte order. |
ArSocket is a layer which allows people to use the sockets networking interface in an operating system independent manner. All of the standard commonly used socket functions are implemented. This class also contains the file descriptor which identifies the socket to the operating system.
In Windows, the networking subsystem needs to be initialized and shutdown individyaly by each program. So when a program starts they will need to call the static function ArSocket::init() and call ArSocket::shutdown() when it exits. For programs that use Aria::init() and Aria::uninit() calling the ArSocket::init() and ArSocket::shutdown() is unnecessary. The Aria initialization functions take care of this. These functions do nothing in Linux.
|
Constructor which connects to a server. Constructs the socket and connects it to the given host.
|
|
Constructor which opens a server port. Constructs the socket and opens it as a server port.
|
|
Copy socket structures. Copy socket structures. Copy from one Socket to another will still have the first socket close the file descripter when it is destructed. |
|
Initialize the network layer. In Windows, the networking subsystem needs to be initialized and shutdown individyaly by each program. So when a program starts they will need to call the static function ArSocket::init() and call ArSocket::shutdown() when it exits. For programs that use Aria::init() and Aria::uninit() calling the ArSocket::init() and ArSocket::shutdown() is unnecessary. The Aria initialization functions take care of this. These functions do nothing in Linux. |
|
Read from the socket.
|
|
Reads a string from the socket.
|
|
Shutdown the network layer. In Windows, the networking subsystem needs to be initialized and shutdown individyaly by each program. So when a program starts they will need to call the static function ArSocket::init() and call ArSocket::shutdown() when it exits. For programs that use Aria::init() and Aria::uninit() calling the ArSocket::init() and ArSocket::shutdown() is unnecessary. The Aria initialization functions take care of this. These functions do nothing in Linux. |
|
Transfer ownership of a socket. transfer() will transfer ownership to this socket. The input socket will no longer close the file descriptor when it is destructed. |
|
Write to the socket.
|
|
Writes a string to the socket. This cannot write more than 2048 number of bytes
|