Public Member Functions
TCPSocket Class Reference

#include <TCPSocket.h>

Inheritance diagram for TCPSocket:
Socket

Public Member Functions

 TCPSocket ()
 
template<typename S >
 TCPSocket (S *stack)
 
virtual ~TCPSocket ()
 
nsapi_error_t connect (const char *host, uint16_t port)
 
nsapi_error_t connect (const SocketAddress &address)
 
nsapi_size_or_error_t send (const void *data, nsapi_size_t size)
 
nsapi_size_or_error_t recv (void *data, nsapi_size_t size)
 
- Public Member Functions inherited from Socket
virtual ~Socket ()
 
nsapi_error_t open (NetworkStack *stack)
 
nsapi_error_t close ()
 
nsapi_error_t bind (uint16_t port)
 
nsapi_error_t bind (const char *address, uint16_t port)
 
nsapi_error_t bind (const SocketAddress &address)
 
void set_blocking (bool blocking)
 
void set_timeout (int timeout)
 
void sigio (mbed::Callback< void()> func)
 
void attach (mbed::Callback< void()> func)
 
template<typename T , typename M >
void attach (T *obj, M method)
 

Detailed Description

TCP socket connection

Constructor & Destructor Documentation

TCPSocket::TCPSocket ( )

Create an uninitialized socket

Must call open to initialize the socket on a network stack.

template<typename S >
TCPSocket::TCPSocket ( S *  stack)
inline

Create a socket on a network interface

Creates and opens a socket on the network stack of the given network interface.

Parameters
stackNetwork stack as target for socket
TCPSocket::~TCPSocket ( )
virtual

Destroy a socket

Closes socket if the socket is still open

Member Function Documentation

nsapi_error_t TCPSocket::connect ( const char *  host,
uint16_t  port 
)

Connects TCP socket to a remote host

Initiates a connection to a remote server specified by either a domain name or an IP address and a port.

Parameters
hostHostname of the remote host
portPort of the remote host
Returns
0 on success, negative error code on failure
nsapi_error_t TCPSocket::connect ( const SocketAddress &  address)

Connects TCP socket to a remote host

Initiates a connection to a remote server specified by the indicated address.

Parameters
addressThe SocketAddress of the remote host
Returns
0 on success, negative error code on failure
nsapi_size_or_error_t TCPSocket::recv ( void *  data,
nsapi_size_t  size 
)

Receive data over a TCP socket

The socket must be connected to a remote host. Returns the number of bytes received into the buffer.

By default, recv blocks until data is sent. If socket is set to non-blocking or times out, NSAPI_ERROR_WOULD_BLOCK is returned immediately.

Parameters
dataDestination buffer for data received from the host
sizeSize of the buffer in bytes
Returns
Number of received bytes on success, negative error code on failure
nsapi_size_or_error_t TCPSocket::send ( const void *  data,
nsapi_size_t  size 
)

Send data over a TCP socket

The socket must be connected to a remote host. Returns the number of bytes sent from the buffer.

By default, send blocks until data is sent. If socket is set to non-blocking or times out, NSAPI_ERROR_WOULD_BLOCK is returned immediately.

Parameters
dataBuffer of data to send to the host
sizeSize of the buffer in bytes
Returns
Number of sent bytes on success, negative error code on failure

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