Program: - 2
1) Using TCP/IP sockets, Write a client-server program to make the
client send the file name and to make the server send back the
contents of the requested file if present.
Sockets are a protocol independent method of crea ng a connec on between process sockets can
be either
Connec on based or connec onless: Is a connec on stabilized before communica on orders
each packet describe the des na on?
Packet based or stream based: Are there message boundaries or is it one stream?
Reliable or unreliable: Can message be lost, Duplicated, reorder, or corrupted?
Sockets characteris c
Socket are characterized by their domain, Type and transport protocol. Common domains are:
AF_INET: IPv4 Internet protocols
AF_INET6: IPv6 Internet protocols
AF_UNIX: Local communication (on same system)
Common socket types are:
SOCK_STREAM: Provides a reliable, connection-oriented byte stream. Example: TCP.
SOCK_DGRAM: Provides connectionless, unreliable messages of a fixed maximum length.
Example: UDP.
Common protocols are:
TCP (Transmission Control Protocol): Reliable, connection-based protocol using
SOCK_STREAM.
UDP (User Datagram Protocol): Unreliable, connectionless protocol using
SOCK_DGRAM.
Use of sockets:
Connection–based sockets communicate client-server: the server waits for a connection from
the client
Connectionless sockets are peer-to-peer: each process is symmetric.
Socket APIs
➤ socket: creates a socket of a given domain, type, protocol (buy a phone)
➤ bind: assigns a name to the socket (get a telephone number)
➤ listen: specifies the number of pending connections that can be queued for a server socket.
(call waiting allowance)
➤ accept: server accepts a connection request from a client (answer phone)
➤ connect: client requests a connection request to a server (call)