![]() |
Network Dual-Stack Component
Version 7.0 (Beta)
MDK-Professional Middleware for IPv4 and IPv6 Networking
|
BSD Socket functions and communication flow. More...
BSD Socket functions and communication flow.
The following table shows the available API functions for BSD sockets.
Function | Description |
---|---|
accept | Accepts a connection request queued for a listening socket. |
bind | Assigns a name (local address) to a socket. |
closesocket | Closes an existing socket and releases a socket descriptor. |
connect | Establishes connection between the endpoints on stream sockets. |
gethostbyname | Retrieves host address corresponding to a host name from a host database. |
getpeername | Retrieves the address of the peer to which a socket is connected. |
getsockname | Retrieves the local address of the socket. |
ioctlsocket | Sets or retrieves some of the operating parameters on a socket. |
listen | Sets the socket in a listen mode. |
recv | Receives incoming data that has been queued for a socket. |
recvfrom | Receives incoming data on a datagram socket. |
send | Sends outgoing data on a socket. |
sendto | Sends outgoing data on a datagram socket to destination address. |
setsockopt | Manipulate options for the socket. |
socket | Creates a communication socket. |
The image below explains the basic communication flow using BSD sockets with TCP.
The BSD server creates a socket, uses bind to attach that socket to a port, and configures it as a listening socket. This allows the server to receive incoming connection requests. Afterwards, accept is called, which will block the socket, until an incoming connection request is received. When accept returns, the SOCKADDR structure will have been filled out with the originating IP Address and port of the incoming connection. Then, accept creates a new socket, which is then used to receive data until the connection is closed by the other side.
Code Example for the BSD Server
The BSD Client creates a socket calls connect, because TCP requires a negotiated connection. Afterwards, send is called to send the data to the server. Note that bind is never called, because the stack will pick a random port and an appropriate IP address. To finish the communication, the client calls closesocket.
Code Example for the BSD Client