ObjFW
 All Classes Functions Variables
Instance Methods | Class Methods | List of all members
OFTCPSocket Class Reference

A class which provides functions to create and use TCP sockets. More...

#import <OFTCPSocket.h>

Inheritance diagram for OFTCPSocket:
OFStreamSocket OFStream OFObject <OFCopying> <OFObject>

Instance Methods

(void) - setSOCKS5Host:
 Sets the host to use as a SOCKS5 proxy.
 
(OFString *) - SOCKS5Host
 Returns the host to use as a SOCKS5 proxy.
 
(void) - setSOCKS5Port:
 Sets the port to use on the SOCKS5 proxy.
 
(uint16_t) - SOCKS5Port
 Returns the port to use on the SOCKS5 proxy.
 
(void) - connectToHost:port:
 Connect the OFTCPSocket to the specified destination.
 
(void) - asyncConnectToHost:port:target:selector:
 Asyncronously connect the OFTCPSocket to the specified destination.
 
(uint16_t) - bindToHost:port:
 Bind the socket on the specified port and host.
 
(void) - listenWithBackLog:
 Listen on the socket.
 
(void) - listen
 Listen on the socket.
 
(OFTCPSocket *) - accept
 Accept an incoming connection.
 
(void) - asyncAcceptWithTarget:selector:
 Asyncronously accept an incoming connection.
 
(void) - setKeepAlivesEnabled:
 Enable or disable keep alives for the connection.
 
(OFString *) - remoteAddress
 Returns the remote address of the socket.
 
(BOOL) - isListening
 Returns whether the socket is a listening socket.
 

Class Methods

(void) + setSOCKS5Host:
 Sets the global SOCKS5 proxy host to use when creating a new socket.
 
(OFString *) + SOCKS5Host
 Returns the host to use as a SOCKS5 proxy when creating a new socket.
 
(void) + setSOCKS5Port:
 Sets the global SOCKS5 proxy port to use when creating a new socket.
 
(uint16_t) + SOCKS5Port
 Returns the port to use as a SOCKS5 proxy when creating a new socket.
 
- Class Methods inherited from OFStreamSocket
(instancetype) + socket
 Returns a new, autoreleased OFTCPSocket.
 

Detailed Description

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.

Method Documentation

- (OFTCPSocket *) accept

Accept an incoming connection.

Returns
An autoreleased OFTCPSocket for the accepted connection.
- (void) asyncAcceptWithTarget: (id)  target
selector: (SEL)  selector 

Asyncronously accept an incoming connection.

Parameters
targetThe target on which to execute the selector when a new connection has been accepted. The method returns whether the next incoming connection should be accepted by the specified block as well.
selectorThe selector to call on the target. The signature must be BOOL (OFTCPSocket *socket, OFTCPSocket *acceptedSocket, OFException *exception).
- (void) asyncConnectToHost: (OFString*)  host
port: (uint16_t)  port
target: (id)  target
selector: (SEL)  selector 

Asyncronously connect the OFTCPSocket to the specified destination.

Parameters
hostThe host to connect to
portThe port on the host to connect to
targetThe target on which to call the selector once the connection has been established
selectorThe selector to call on the target. The signature must be void (OFTCPSocket *socket, OFException *exception).
- (uint16_t) bindToHost: (OFString*)  host
port: (uint16_t)  port 

Bind the socket on the specified port and host.

Parameters
hostThe host to bind to. Use "0.0.0.0" for IPv4 or @"::" for IPv6 to bind to all.
portThe port to bind to. If the port is 0, an unused port will be chosen, which can be obtained using the return value.
Returns
The port the socket was bound to
- (void) connectToHost: (OFString*)  host
port: (uint16_t)  port 

Connect the OFTCPSocket to the specified destination.

Parameters
hostThe host to connect to
portThe port on the host to connect to
- (BOOL) isListening

Returns whether the socket is a listening socket.

Returns
Whether the socket is a listening socket
- (void) listenWithBackLog: (int)  backLog

Listen on the socket.

Parameters
backLogMaximum length for the queue of pending connections.
- (OFString *) remoteAddress

Returns the remote address of the socket.

Only works with accepted sockets!

Returns
The remote address as a string
- (void) setKeepAlivesEnabled: (BOOL)  enable

Enable or disable keep alives for the connection.

Parameters
enableWhether to enable or disable keep alives for the connection
+ (void) setSOCKS5Host: (OFString*)  host

Sets the global SOCKS5 proxy host to use when creating a new socket.

Parameters
hostThe host to use as a SOCKS5 proxy when creating a new socket
- (void) setSOCKS5Host: (OFString *)  host

Sets the host to use as a SOCKS5 proxy.

Parameters
hostThe host to use as a SOCKS5 proxy
+ (void) setSOCKS5Port: (uint16_t)  port

Sets the global SOCKS5 proxy port to use when creating a new socket.

Parameters
portThe port to use as a SOCKS5 proxy when creating a new socket
- (void) setSOCKS5Port: (uint16_t)  port

Sets the port to use on the SOCKS5 proxy.

The default port is 1080.

Parameters
portThe port to use on the SOCKS5 proxy
+ (OFString*) SOCKS5Host

Returns the host to use as a SOCKS5 proxy when creating a new socket.

Returns
The host to use as a SOCKS5 proxy when creating a new socket
- (OFString*) SOCKS5Host

Returns the host to use as a SOCKS5 proxy.

Returns
The host to use as a SOCKS5 proxy
+ (uint16_t) SOCKS5Port

Returns the port to use as a SOCKS5 proxy when creating a new socket.

Returns
The port to use as a SOCKS5 proxy when creating a new socket
- (uint16_t) SOCKS5Port

Returns the port to use on the SOCKS5 proxy.

Returns
The port to use on the SOCKS5 proxy

The documentation for this class was generated from the following files: