You are viewing an older revision! See the latest version

Socket

Table of Contents

  1. TCP Socket
  2. UDP Socket

The Socket library is included within the Networking libraries (Ethernet Interface and VodafoneK3770 Interface).

The mbed C++ Socket API is inspired by the BSD socket API but makes it really simpler to use.

TCP Socket

#include "TCPSocket.h"

Import library

Public Member Functions

TCPSocket ()
Instantiate a TCP Socket.
int connect (char *host, int port, int timeout=0)
Connect the TCP Socket to the following host.
int bind (int port)
Bind a socket to a specific port.
int listen (int max)
Start listening for incoming connections.
int accept ( TCPSocket &socket, char **host, int *port, int timeout=0)
Accept a new connection.
int send (char *data, int length, int timeout=0)
Send data to the remote host.
int receive (char *data, int length, int timeout=0)
Receive data from the remote host.
int close ()
Close the socket.

UDP Socket

#include "UDPSocket.h"

Import library

Public Member Functions

UDPSocket ()
Instantiate a UDP Socket.
int bind (int port)
Bind a socket to a specific port.
int sendTo (char *data, int length, char *host, int port, int timeout=0)
Send data to a remote host.
int receiveFrom (char *data, int length, char **host, int *port, int timeout=0)
Receive data from a remote host.
int close ()
Close the socket.

All wikipages