Beruflich Dokumente
Kultur Dokumente
Introduction :
SERVER CLIENT
Socket() Socket()
Bind()
Bind()
Recvfrom() Sendto()
Sendto() Recvfrom()
SERVER :
Create endpoint (socket())
bind address (bind())
transfer data (sendto() recvfrom())
CLIENT :
Create endpoint(socket())
bind address (bind))
connect to server (connect())
transfer data (sendto() recvfrom())
1|Page
Created By : Kishor (gmkishor@yahoo.co.uk)
What Is UDP?
UDP is a minimal message-oriented transport layer that uses ports to provide packet-switched
application-to-application communication over a network. UDP encapsulates messages – or
packets – in the form of a datagram (see Figure 2).
A datagram is logically arranged in two parts – the datagram header and message. Each
datagram header is further broken down into four sections, as illustrated in Figure 2. The
minimum length of a single UDP datagram is the size of the datagram header, or 8 bytes.
UDP is characterized by this minimal overhead and small packet size, which translates to
higher throughput when compared to TCP. However, because inherent error checking and the
guarantee of data receipt are sacrificed to achieve increased throughput, TCP becomes the
more beneficial choice in applications where large message size or transmission reliability is
important.
5X smaller packet sizes than TCP Large amount of data transfer with acceptable data loss
Less network traffic Fast data streaming
Broadcast and multicast support Reduction of network connections
2|Page
Created By : Kishor (gmkishor@yahoo.co.uk)
TCP Socket versus UDP Socket
Transmission Control Protocaol Socket
Client-Server architecture
Connection-oriented with error control
3|Page
Created By : Kishor (gmkishor@yahoo.co.uk)
Creating a UDP Datagram Socket Application
A UDP server does not have to listen for and accept client connections, and a UDP client does not
have to connect to a server. The following illustration shows the interaction between the UDP
server and UDP client.
To prepare for association with a client, a UDP datagram server need only create a socket and
bind it to a name when preparing for association with a client.
2. Name the socket with the bind function, using a SOCKADDR_IN structure for
the address parameter.
3. Exchange data with a client using the sendto and recvfrom functions.
The UDP datagram socket server application calls recvfrom to prepare to receive data from a
client Therecvfrom function reads incoming data on unconnected sockets and captures the
address from which the data was sent. To do this, the local address of the socket must be
known.
The sendto function is used on a connectionless socket to send a datagram to a specific peer
socket identified by the to parameter. Successfully completing a sendto function call does not
confirm data was successfully delivered.
4|Page
Created By : Kishor (gmkishor@yahoo.co.uk)