socket interface programming
DESCRIPTION
Socket interface programmingTRANSCRIPT
2.5 SOCKET-INTERFACE PROGRAMMING2.5 SOCKET-INTERFACE PROGRAMMING
1
Computer Communications and Networks
2
Socket: End point of an inter-process communication flow across a computer network.
Different types of sockets :
Stream socket :(connection- oriented socket)
•It provides reliable, connected networking service
•Error free; no out- of- order packets (uses TCP)
•applications: telnet, http, …
Datagram socket :(connectionless socket)
•It provides unreliable, best- effort networking service
•Packets may be lost; may arrive out of order (uses UDP)
•applications: streaming audio/ video
2.5 SOCKET-INTERFACE PROGRAMMING2.5 SOCKET-INTERFACE PROGRAMMING
2.5.1 Socket Interface in C
• In this section, we show how this interface is implemented in the C language.
• The important issue in socket interface is to understand the role of a socket in
communication.
• The socket has no buffer to store data to be sent or received.
• It is capable of neither sending nor receiving data. The socket just acts as a
reference or a label.
• The buffers and necessary variables are created inside the operating system.
3
2.5.1 (continued)
Data Structure for SocketData Structure for Socket
Header FilesHeader Files
Sockets Used for UDPSockets Used for UDP Communication Flow DiagramCommunication Flow Diagram Programming ExamplesProgramming Examples
Communication Using UDPCommunication Using UDP
Communication Using TCPCommunication Using TCP
Sockets Used in TCPSockets Used in TCP Communication Flow DiagramCommunication Flow Diagram
4
Figure 2.58: Socket data structure
5
C language defines a socket as a structure (strcut) and socket structure is made of 5 field .
6
Family : Defines family protocol(how to interpret the addresses and port
number) ,PF_INET ,PF_INET6.
Type : Defines four types of sockets.
SOCK_STREAM (for TCP)
SOCK_DGRAM( for UDP)
SOCK_SEQPACKET (for SCTP)
SOCK_RAW( for application that directly use the services of IP)
Protocol : (defines specific protocol, set to 0 for TCP/IP)
Local Socket Address: Defines local socket address. Socket Address is itself made of the length
field , family field(set to the constant AF_INET for TCP/IP), port number(which defines the
process) and IP address field(which defines the host on which the process is running) . Also
contains an unused field.
Remote Socket Address: Define the remote socket address. Structure is the same as the local
socket address.
The Socket Primitives
7
Figure 2.59: Sockets for UDP communication
8
Figure 2.60: Flow diagram for iterative UDP communication
9
Table 2.22: Echo server program using UDP
10
Table 2.22: Echo server program using UDP (continued)
11
Table 2.23: Echo client program using UDP
12
Table 2.23: Echo client program using UDP (continued)
13
Table 2.23: Echo client program using UDP (continued)
14
Figure 2.61: Sockets used in TCP communication
Create
2
Create5
15
Figure 2.62: Flow diagram for iterative TCP communication
16
Figure 2.63: Flow diagram for data-transfer boxes
17
Figure 2.64: Buffer used for receiving
18
Table 2.24: Echo server program using the services of TCP
2.19
19
Table 2.24: TCP Echo server program(continued)
2.20
20
Table 2.24: TCP Echo server program (continued)
2.21
21
Table 2.25: Echo client program using the services of TCP
2.22
22
Table 2.25: TCP Echo client program (continued)
23
Table 2.24: TCP Echo client program(continued)
24
25
Thank You….Thank You….