ObjFW
|
A class which provides functions to create and use TCP sockets. More...
#include <OFTCPSocket.h>
Public Member Functions | |
void | connectToHost:onPort: (OFString *host,[onPort] uint16_t port) |
uint16_t | bindToPort:onHost: (uint16_t port,[onHost] OFString *host) |
void | listenWithBackLog: (int backlog) |
void | listen () |
OFTCPSocket * | accept () |
void | setKeepAlivesEnabled: (BOOL enable) |
OFString * | remoteAddress () |
BOOL | isListening () |
Protected Attributes | |
BOOL | isListening |
struct sockaddr_storage * | sockAddr |
socklen_t | sockAddrLen |
A class which provides functions to create and use TCP sockets.
To connect to a server, create a socket and connect it. To create a server, create a socket, bind it and listen on it.
OFTCPSocket * OFTCPSocket::accept | ( | ) | [virtual] |
Accept an incoming connection.
uint16_t OFTCPSocket::bindToPort:onHost: | ( | uint16_t | port, |
[onHost] OFString* | host | ||
) | [virtual] |
Bind the socket on the specified port and host.
port | The port to bind to. If the port is 0, an unused port will be chosen, which can be obtained using the return value. |
host | The host to bind to. Use "0.0.0.0" for IPv4 or @"::" for IPv6 to bind to all. |
void OFTCPSocket::connectToHost:onPort: | ( | OFString* | host, |
[onPort] uint16_t | port | ||
) | [virtual] |
Connect the OFTCPSocket to the specified destination.
host | The host to connect to |
port | The port on the host to connect to |
BOOL OFTCPSocket::isListening | ( | ) | [virtual] |
void OFTCPSocket::listen | ( | ) | [virtual] |
Listen on the socket.
void OFTCPSocket::listenWithBackLog: | ( | int | backlog | ) | [virtual] |
Listen on the socket.
backlog | Maximum length for the queue of pending connections. |
OFString * OFTCPSocket::remoteAddress | ( | ) | [virtual] |
Returns the remote address of the socket. Only works with accepted sockets!
void OFTCPSocket::setKeepAlivesEnabled: | ( | BOOL | enable | ) | [virtual] |
Enable or disable keep alives for the connection.