Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The following sections provide sample code describing how sockets work.

...

Although there is a great deal of similarity between the two APIs, the parameters of the two sets of functions differ slightly. The purpose of the following sections is o give developers a first look at Micrium’s functions by providing concrete examples of how to use the API. 


µC/TCPIP Sockets can be accessed and controlled using 3 different APIs set:

...

BSDNet SockNet AppDescription
socket()NetSock_Open()NetApp_SockOpen()Create a datagram (i.e., UDP) or stream (i.e., TCP) type socket.
bind()NetSock_Bind()NetApp_SockBind()Assign network addresses to sockets.
connect()NetSock_Conn()NetApp_SockConn()Connect a local socket to a remote socket address.
listen()NetSock_Listen()NetApp_SockListen()Set a socket to accept incoming connections.
accept()NetSock_Accept()NetApp_SockAccept()Wait for new socket connections on a listening server socket.
recv() / recvfrom()NetSock_RxData() / NetSock_RxDataFrom()NetApp_SockRx()Copy up to a specified number of bytes received from a remote socket into an application memory buffer.
send() / sendto()NetSock_TxData() / NetSock_TxDataTo()NetApp_SockTx()Copy bytes from an application memory buffer into a socket to send to a remote socket.
close()NetSock_Close()NetApp_SockClose()Terminate communication and free a socket.
select()NetSock_Sel()N/ACheck if any sockets are ready for available read or write operations or error conditions.
N/ANetSock_SelAbort()N/A
Abort a select (i.e. unblock task(s) waiting on socket(s) using the select)

...

FunctionDescription
NetApp_SetSockAddr()Setup a socket address from an IPv4 or an IPv6 address.
NetApp_ClientStreamOpen()Open a stream socket for a client using an IPv4 or IPv6 address.
NetApp_ClientStreamOpenByHostname()Open a stream socket for a client using a hostname (resolve the hostname using µC/DNSc + Autoselect remote address)
NetApp_TimeDly_ms()Delay for specified time, in milliseconds.
NetSock_GetConnTransportID()Gets a socket’s transport layer connection handle ID (e.g., TCP connection ID) if available.
NetSock_IsConn()Check if a socket is connected to a remote socket.
NetSock_PoolStatResetMaxUsed()Reset Network Sockets’ statistics pool’s maximum number of entries used.

 


Socket Error Codes

When socket functions return error codes, the error codes should be inspected to determine if the error is a temporary, non-fault condition (such as no data to receive) or fatal (such as the socket has been closed).

...

NET_SOCK_ERR_INVALID_FAMILY
NET_SOCK_ERR_INVALID_PROTOCOL
NET_SOCK_ERR_INVALID_TYPE
NET_SOCK_ERR_INVALID_STATE
NET_SOCK_ERR_FAULT

...


Whenever any of the following fatal error codes are returned by any µC/TCP-IP socket function, that socket must not be accessed by any other socket functions but must also not be closed()’d:

NET_SOCK_ERR_NOT_USED

Socket Error Code List

All the possible error codes returned by the µC/TCP-IP stack are defined in net_err.h. Please refer to net_err.h for more details on any specific error code.