Mistake on this page?
Report an issue in GitHub or email us
Public Member Functions | Protected Member Functions | Protected Attributes | Friends
TCPSocket Class Reference

#include <TCPSocket.h>

Inheritance diagram for TCPSocket:
Socket

Public Member Functions

 TCPSocket ()
 
template<typename S >
 TCPSocket (S *stack)
 
virtual ~TCPSocket ()
 
int join_multicast_group (const SocketAddress &address)
 
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)
 
template<typename S >
nsapi_error_t open (S *stack)
 
nsapi_error_t close ()
 
int join_multicast_group (const SocketAddress &address)
 
int leave_multicast_group (const SocketAddress &address)
 
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)
 
nsapi_error_t setsockopt (int level, int optname, const void *optval, unsigned optlen)
 
nsapi_error_t getsockopt (int level, int optname, void *optval, unsigned *optlen)
 
void sigio (mbed::Callback< void()> func)
 
void attach (mbed::Callback< void()> func)
 
template<typename T , typename M >
void attach (T *obj, M method)
 

Protected Member Functions

virtual nsapi_protocol_t get_proto ()
 
virtual void event ()
 
- Protected Member Functions inherited from Socket
int modify_multicast_group (const SocketAddress &address, nsapi_socket_option_t socketopt)
 

Protected Attributes

volatile unsigned _pending
 
rtos::EventFlags _event_flag
 
bool _read_in_progress
 
bool _write_in_progress
 
- Protected Attributes inherited from Socket
NetworkStack_stack
 
nsapi_socket_t _socket
 
uint32_t _timeout
 
mbed::Callback< void()> _event
 
mbed::Callback< void()> _callback
 
rtos::Mutex _lock
 

Friends

class TCPServer
 

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
int TCPSocket::join_multicast_group ( const SocketAddress address)
inline

Override multicast functions to return error for TCP

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 some data is received. If socket is set to non-blocking or times out, NSAPI_ERROR_WOULD_BLOCK can be returned to indicate no data.

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. If no data is available to be received and the peer has performed an orderly shutdown, recv() returns 0.
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 all data is sent. If socket is set to non-blocking or times out, a partial amount can be written. NSAPI_ERROR_WOULD_BLOCK is returned if no data was written.

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:
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.