Np unit2
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Np unit2

on

  • 2,749 views

 

Statistics

Views

Total Views
2,749
Views on SlideShare
2,739
Embed Views
10

Actions

Likes
1
Downloads
66
Comments
0

2 Embeds 10

http://vamsinp.blogspot.in 8
http://vamsinp.blogspot.com 2

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Np unit2 Presentation Transcript

  • 1. What is a socket?An interface between application and network The application creates a socket The socket type dictates the style of communication  reliable vs. best effort  connection-oriented vs. connectionlessOnce configured the application can pass data to the socket for network transmission receive data from the socket (transmitted through the network by some other host)
  • 2. What is Socket ?Endpoint of any connectionTwo Types : TCP UDPIdentified by Two values An IP Address A Port Number
  • 3. Two essential types of sockets  SOCK_STREAM  SOCK_DGRAM  reliable delivery  unreliable delivery  in-order guaranteed  no order guarantees  connection-oriented  no notion of “connection” – app  bidirectional indicates dest. for each packet  can send or receive App App D13 2 1 socket Dest. 3 2 1 socket D2 D3 4
  • 4. SERVER SIDE socket()Socket Functions Well known bind() port CLIENT SIDE listen() socket() accept() Connection establishment connect() Blocks until (TCP three-way handshake) connection from client write() Data (request) read() Process request Data (reply) write() read() End-of-file notification close() read() Running an App close()
  • 5. Socket Creation in C: socketint s = socket(domain, type, protocol); s: socket descriptor, an integer (like a file-handle) domain: integer, communication domain  e.g., AF_INET (IPv4 protocol) – typically used type: communication type  SOCK_STREAM: reliable, 2-way, connection-based service  SOCK_DGRAM: unreliable, connectionless,
  • 6. Socket Creation in C: socket protocol: specifies protocol (see file /etc/protocols for a list of options) – usually set to 0 to select the system’s default for the given combination of family and type.NOTE: socket call does not specify where data will be coming from, nor where it will be going to – it just creates the interface!
  • 7. Protocol family constantsFamily DescriptionAF_INET IPv4 protocolAF_INET6 IPv6 protocolAF_LOCAL UNIX DOMAIN PROTOCOLAF_ROUTE Routing socketAF_KEY Key socket
  • 8. Type of socketType DescriptionSOCK_STREAM STREAM socketSOCK_DGRAM Datagram socketSOCK_SEQPACKET Sequenced packet socketSOCK_RAW Raw socket
  • 9. Protocol of socket protocol description IPPROTO_TCP TCP transport protocol IPPROTO_UDP UDP transport protocol IPPROTO_SCTP SCTP transport protocol
  • 10. Addresses, Ports and SocketsLike apartments and mailboxes  You are the application  Your apartment building address is the address  Your mailbox is the port  The post-office is the network  The socket is the key that gives you access to the right mailbox (one difference: assume outgoing mail is placed by you in your mailbox)
  • 11. IPv4 Socket Address StructureStruct in_addr{ in_addr_t s_addr; /*32bit IPv4 address*/ }; /*network byte ordered*/struct sockaddr_in { uint8_t sin_len; /* length of structure(16) */ sa_family_t sin_family; /* AF_INET */ in_port_t sin_port; /* 16bit TCP or UDP port number */ /*network byte ordered*/ struct in_addr sin_addr; /* 32bit IPv4 address */ /*network byte ordered*/ char sin_zero[8]; /* unused */}; /* included in <netinet/in.h> */
  • 12. Socket Address StructureLength field simplifies the handling of variable-length socket address structures.Used with routing socket.In_addr_t datatype must be an unsigned integer type of at least 32 bits.
  • 13. DatatypeDatatype Description HeaderInt8_t Signed 8-bit integer <sys/types.h>Uint8_t unsigned 8-bit integer <sys/types.h>Int16_t Signed 16-bit integer <sys/types.h>Uint16_t unsigned 16-bit integer <sys/types.h>Int32_t Signed 32-bit integer <sys/types.h>Uint32_t unsigned 32-bit integer <sys/types.h>Sa_family_t Add. Family of socket add <sys/socket.h> structSocklen_t Length of socket add struct <sys/socket.h>In_addr_t IPV4 address, uint32_t <netinet/in.h>
  • 14. Generic Socket Address structureA Socket address structure must be passed by referencesocket function that takes one of these pointers as an argument must deal with socket address structures from any of the supported protocol families.How to declare the type of pointerSoln : void *Define Generic socket address structure<sys/socket.h>
  • 15. Generic Socket Address structureStruct sockaddr { uint8_t sa_len; sa_family_t sa_family; char sa_data[14];/* protocol specific address*/ }; From an application programmers point of view, the only use of these generic socket address structures is to cast pointers to protocol-specific structures.
  • 16. IPv6 Socket Address StructureStruct in6_addr{ uint8_t s6_addr[16]; /*128bit IPv6 address*/ }; /*network byte ordered*/#define SIN6_LEN /* required for compile-time tests */struct sockaddr_in6 { uint8_t sin6_len; /* length of structure(24) */ sa_family_t sin6_family; /* AF_INET6*/ in_port_t sin6_port; /* Transport layer port# */ /*network byte ordered*/ uint32_t sin6_flowinfo; /* priority & flow label */ /*network byte ordered*/ struct in6_addr sin6_addr; /* IPv6 address */ /*network byte ordered*/}; /* included in <netinet/in.h> */
  • 17. New Generic Socket Address structureStruct sockaddr { uint8_t sa_len; sa_family_t sa_family; /* implementation dependent elements to provide 1. alignment 2. enough storage to hold any type of socket address that the system supports */ };
  • 18. sockaddr_storage different from struct sockaddrin two ways:If any socket address structures that the system supports have alignment requirements, the sockaddr_storage provides the strictest alignment requirement.The sockaddr_storage is large enough to contain any socket address structure that the system supports.
  • 19. Comparison of socket address structure
  • 20. Value-result ArgumentsAccept , recvfrom , getpeername pass socket address structure from kernel to the process.Size changes from an int to pointer to an integer is because the size is both a value when the function is called and Result when function returns.connect (sockfd, (SA *) &serv, sizeof(serv));getpeername(unixfd, (SA *) &cli, &len);
  • 21. Address and port byte-orderingAddress and port are stored as integers  u_short sin_port; (16 bit)  in_addr sin_addr; (32 bit) Problem: different machines / OS’s use different word orderings • little-endian: lower bytes first • big-endian: higher bytes first these machines may communicate with one another over the network Big-Endian Little-Endian machine machine G !! !12.40.119.128 ON40 12128.119.40.12 128 R 128 119 40 12 W 119 23
  • 22. Solution: Network Byte-OrderingDefs: Host Byte-Ordering: the byte ordering used by a host (big or little) Network Byte-Ordering: the byte ordering used by the network – always big-endianAny words sent through the network should be converted to Network Byte-Order prior to transmission (and back to Host Byte-Order once received)
  • 23. Byte Ordering FunctionsprogramTwo types of Byte Ordering Little-endian Byte Ordering Address A+1 Address A MSB LSB Big-endian Byte Ordering Address A Address A+1 MSB LSB
  • 24. determine host byte order int main(int argc, char **argv) { union { short s; char c[sizeof(short)]; } un; un.s = 0x0102; printf("%s: ", CPU_VENDOR_OS); if (sizeof(short) == 2) { if (un.c[0] == 1 && un.c[1] == 2) printf("big-endiann"); else if (un.c[0] == 2 && un.c[1] == 1) printf("little-endiann"); else printf("unknownn"); } else printf("sizeof(short) = %dn", sizeof(short)); exit(0);
  • 25. Byte Ordering Functions<netinet/in.h>uint16_t htons(uint16_t host16val); -- convert 16-bit value from host to network order, used for the port number.uint32_t htonl(uint32_t host32val); -- convert 32-bit value from host to network order, used for the Ipv4 address.uint16_t ntohs(uint16_t network16val); -- convert 16-bit value from network to host order.uint32_t ntohl(uint32_t network32val); -- convert 32-bit value from network to host order.
  • 26. Byte Ordering Functions#include<strings.h>Void bzero(void *dest, size_t nbytes); -- SETS THE SPECIFIED NO. OF BYTES TO O IN THE DESTINATION.Void bcopy(const void *src, void *dest, size_t nbytes); -- copies nbytes of src to dest.int bcmp(const void *ptrl, const void *ptr2, size_t nbytes); -- compare nbytes of the two strings, Returns 0 if they match, >0 if ptr1 >ptr2, < 0 if ptr1 < ptr2.
  • 27. void *memset(void *dest, int c, size_t nbytes); ---- writes value c in the destination ----bytes of dest. Returns dest.void *memcpy(void *dest, const void *src, size_t nbytes); ---- copies nbytes of src to dest. Returns dest.int memcmp(const void *ptrl, const void *ptr2, size_t nbutes); ---- compare nbytes of the two strings, Returns 0 if they match, >0 if ptr1 >ptr2, < 0 if ptr1 < ptr2.
  • 28. Inet_aton, inet_addr, inet_ntoaAn internet address is written as: “192. 43. 234.1”, saved as a character string. The functions require their number as a 32-bit binary value.<arpa/inet.h>int inet_aton(const char *strptr, struct in_addr * addrptr); -- returns 1, 0 on error. Converts from a dotted-decimal string to a network address.
  • 29. Inet_aton, inet_addr, inet_ntoaIn_addr_t inet_addr(const char *strptr); -- Converts from a dotted-decimal string to 32-bit interger as return value. --INADDR_NONE IF ERRORschar *inet_ntoa (struct in_addr addrptr); -- Returns a pointer to a dotted-decimal string, given a valid network address.
  • 30. Inet_pton functions #include<arpa/inet.h>Convert strptr ( which is in presentation form ) to numeric form and store it into addrptr.int inet_pton(int family, const char *strptr, void *addrptr); -- returns 1 if OK, 0 if invalid input format, -1 on error.
  • 31. inet_ntop functionsConst char *inet_ntop (int family, const void *addrptr, char *strptr, size_t len); -- returns pointer to result if OK, NULL on error. --len argument is the size of the destination, to prevent the function from overflowing the caller’s buffer Two functions supports both IPv4 and IPv6 protocol
  • 32. Sock_ntop functionA basic problem with inet_ntop is that it requires the caller to pass a pointer to a binary address.This address is normally contained in a socket address structure,Requiring the caller to know the format of the structure and the address family.
  • 33. Sock_ntop functionstruct sockaddr_in addr; inet_ntop(AF_INET, &addr.sin_addr, str, sizeof(str));For IPV6 struct sockaddr_in6 addr6; inet_ntop(AF_INET6, &addr6.sin6_addr, str, sizeof(str));sock_ntop that takes a pointer to a socket address structure, looks inside the structure, and calls the appropriate function to return the presentation format of the address.
  • 34. Sock_ntop functionchar *sock_ntop(const struct sockaddr *sockaddr, socklen_t addrlen); Returns: non-null pointer if OK, NULL on errorsockaddr points to a socket address structure whose length is addrlen. The function uses its own static buffer to hold the result and a pointer to this buffer is the return value.
  • 35. sock_ntop and related functions.int sock_bind_wild(int sockfd, int family); Returns: 0 if OK, -1 on error sock_bind_wild binds the wildcard address and an ephemeral port to a socket.
  • 36. sock_ntop and related functions.sock_cmp_addr compares the address portion of two socket address structures int sock_cmp_addr(const struct sockaddr *sockaddr1,const struct sockaddr *sockaddr2, socklen_t addrlen); Returns: 0 if addresses are of the same family and ports are equal, else nonzero
  • 37. sock_ntop and related functionsint sock_cmp_port(const struct sockaddr *sockaddr1,const struct sockaddr *sockaddr2, socklen_t addrlen); Returns: 0 if addresses are of the same family and ports are equal, else nonzerosock_cmp_port compares the port number of two socket address structures.
  • 38. sock_ntop and related functions sock_get_port returns just the port number int sock_get_port(const struct sockaddr *sockaddr, socklen_t addrlen); Returns: non-negative port number for IPv4 or IPv6 address, else -1
  • 39. sock_ntop and related functionschar *sock_ntop_host(const struct sockaddr *sockaddr, socklen_t addrlen); Returns: non-null pointer if OK, NULL on errorsock_ntop_host converts just the host portion of a socket address structure to presentation format (not the port number).
  • 40. sock_ntop and related functionsvoid sock_set_addr(const struct sockaddr *sockaddr, socklen_t addrlen, void *ptr);sock_set_addr sets just the address portion of a socket address structure to the value pointed to by ptr
  • 41. sock_ntop and related functionsvoid sock_set_port(const struct sockaddr *sockaddr, socklen_t addrlen, int port) sock_set_port sets just the port number of a socket address structurevoid sock_set_wild(struct sockaddr *sockaddr, socklen_t addrlen); sock_set_wild sets the address portion of a socket address structure to the wildcard
  • 42. readn, writen, and readline FunctionsA read or write on a stream socket might input or output fewer bytes than requested.Buffer limits might be reached for the socket in the kernel.#include "unp.h“ssize_t readn(int filedes, void *buff, size_t nbytes);ssize_t writen(int filedes, const void *buff, size_t nbytes);ssize_t readline(int filedes, void *buff, size_t maxlen);All return: number of bytes read or written, –1 on error
  • 43. readn function: Read n bytes from a descriptor.#include "unp.h" ssize_t readn(int fd, void *vptr, size_t n) { size_t nleft; ssize_t nread; char *ptr; ptr = vptr; nleft = n; while (nleft > 0) { if ( (nread = read(fd, ptr, nleft)) < 0) { if (errno == EINTR) nread = 0; /* and call read() again */ else return (-1); } else if (nread == 0) break; /* EOF */ nleft -= nread; ptr += nread; }
  • 44. writen function: Write n bytes to a descriptor ssize_t writen(int fd, const void *vptr, size_t n){ size_t nleft; ssize_t nwritten; const char *ptr; ptr = vptr; nleft = n; while (nleft > 0) { if ( (nwritten = write(fd, ptr, nleft)) <= 0) { if (nwritten < 0 && errno == EINTR) nwritten = 0; /* and call write() again */ else return (-1); /* error */ } nleft -= nwritten; ptr += nwritten; } return (n); }
  • 45. readline function: Read a text line from a descriptor, one byte at a time. ssize_t readline(int fd, void *vptr, size_t maxlen) { ssize_t n, rc; char c, *ptr; ptr = vptr; for (n = 1; n < maxlen; n++) { again : if ( (rc = read(fd, &c, 1)) == 1) { *ptr++ = c; if (c == n) break; /* newline is stored, like fgets() */ } else if (rc == 0) { *ptr = 0; return (n - 1); /* EOF, n - 1 bytes were read */ } else { if (errno == EINTR) goto again; return (-1); /* error, errno set by read() */ } } *ptr = 0; /* null terminate like fgets() */ return (n); }
  • 46. Example – Daytime Server/Client Application protocol Daytime client Daytime server Socket API Socket API TCP protocol TCP TCP IP protocol IP IP MAC-level protocol MAC driver MAC driver Actual data flow MAC = media Network access control
  • 47. Files to be createdClient STRING Server Client ServerClient source file - client.cServer source file - server.cHeader file - header.h
  • 48. Running an ApplicationCompile and run server file ( you can run it as a background process too) e.g. $cc server.c $./a.out 2345 &Compile and Run client file e.g. $cc client.c $./a.out 172.16.2.2 2345 Thu March 05 15:50:00 2009 Back
  • 49. abstract Socket function connect function bind function listen function accept function fork and exec function concurrent server close function getsockname and getpeername function
  • 50. SERVER SIDE socket()Socket Functions Well known bind() port CLIENT SIDE listen() socket() accept() Connection establishment connect() Blocks until (TCP three-way handshake) connection from client write() Data (request) read() Process request Data (reply) write() read() End-of-file notification close() read() Running an App close()
  • 51. #include <sys/socket.h>int socket(int family, int type, int protocol); returns:nonnegative descriptor if OK, -1 on error==>Normaly the protocol argument to the socket function is set to 0 exept for raw socket.
  • 52. connect Function #include <sys/socket.h>int connect(int sockfd, const struct sockaddr *servaddr, socklen_t addrlen); Returns : 0 if successful connect, -1 otherwise sockfd: integer, socket to be used in connection  struct sockaddr: address of passive participant  integer, sizeof(struct) (If connect fails, the SYN_SENT socket is no longer useable.)
  • 53. Connection Setup (SOCK_STREAM)A connection occurs between two kinds of participants passive: waits for an active participant to request connection active: initiates connection request to passive sideOnce connection is established, passive and active participants are “similar” both can send & receive data either can terminate the connection
  • 54. Connect functionReturn error ETIMEOUT : no response from server RST : server process is not running EHOSTUNREACH : client’s SYN unreachable from some intermediate router.
  • 55. Error Return by ConnectIf the client TCP receives no response to its SYN segment, ETIMEDOUT is returned.If the server’s response to the client’s SYN is a reset (RST), this indicates that no process is waiting for connections on the server host at the port specified. Hard error  ECONNREFUSED is returned to the client as soon as the RST is received.
  • 56. Error Return by ConnectThree conditions that generate an RST are: When a SYN arrives for a port that has no listening server When TCP wants to abort an existing connection When TCP receives a segment for a connection that does not exist.
  • 57. Error Return by ConnectICMP destination unreachable received in response to client TCP’s SYN (maybe due to transient routing problem), resend SYN timeout after 75 sec, returns EHOSTUNREACH or ENETUNREACH
  • 58. connect Function: Three-Way Handshake• No bind before connect :The kernel chooses the source IP, if necessary, and an ephemeral port (for the client).Hard error: RST received in response to client TCP’s SYN (server notrunning) returns ECONNREFUSEDSoft error:1. no response to client TCP’s SYN, resend SYN, timeout after 75 sec (in 4.4BSD), returns ETIMEOUT2. ICMP destination unreachable received in response to client TCP’s SYN (maybe due to transient routing problem), retx SYN, timeout after 75 sec, returns EHOSTUNREACH)
  • 59. The bind function Assigns a local protocol address to a socket. int status = bind(int sockid, const struct sockaddr &myaddr, socklen_t addrlen); status: error status, = -1 if bind failed, 0 if OK. sockid: integer, socket descriptor myaddr: struct sockaddr, the (IP) address and port of the machine (address usually set to INADDR_ANY – chooses a local address) addrlen: the size (in bytes) of the addrport structure
  • 60. bind FunctionUsually servers bind themselves to their well-known ports.RPC servers let kernel choose ephemeral ports which are then registered with the RPC port mapper.Normally, TCP client does not bind an IP address to its socket.If a TCP server does not bind an IP address to its socket, the kernel uses the destination IP address of the client’s SYN as the server’s source IP address
  • 61. bind FunctionTable summarizes the values to which weset sin_addr and sin_port depending on thedesired result. Process specifies IP address port Result Wildcard 0 kernel chooses IP addr and port wildcard nonzero kernel chooses IP addr, process specifies port local IP addr 0 kernel chooses port, process specifies IP addr local IP addr nonzero process specifies IP addr and port
  • 62. bind FunctionWildcard address is specified by the constant INADDR_ANY whose value is normally 0.To obtain value of the ephemeral port assigned by the kernel, we must call getsockname to return the protocol address.
  • 63. listen function#include <sys/socket.h>int listen(int sockfd, int backlog); Returns:0 if OK, -1 on error==>This function is called only by a TCP server The listen function converts an unconnected socket into a passive socket, indicating that the kernel should accept incoming connection requests directed to this socket. backlog =>specify the maximum number of connections that the kernel should queue for this socket. If the queues are full when client SYN arrives, TCP server ignore the SYN, it does not send RST.
  • 64. listen function● An incomplete connection queue, which contains an entryfor each SYN that has arrived from a client for which theserver is awaiting completion of the TCP three-wayhandshake● A completed connection queue, which contains an entry foreach client with whom the TCP three-way handshake hascompleted
  • 65. Backlog argument to the listen function has historically specified the maximumvalue for the sum of both queues
  • 66. listen FunctionBacklog argument to listen function has specified the maximum value for the sum of both queuesBerkeley derived : multipied by 1.5Do not specify backlog of 0What value should the application specify?Allow Command line or an environment variable to override default.
  • 67. Listen that allows an environment var to specify backlog Void Listen(int fd, int backlog) { char *ptr; if ((ptr=getenv(“LISTENQ”))!=NULL) backlog=atoi(ptr); if (listen(fd,backlog)<0) printf(“listen error”); }
  • 68. listen FunctionIf the queues are full when a client SYN arrives, TCP ignores the arriving SYN : it does not send an RST.Data that arrives after the three way handshake completes, but before the server call accept, should be queued by the server TCP, up to the size of the connected socket’s receive buffer.
  • 69. accept function#include <sys/socket.h>int accept(int sockfd, struct sockaddr *cliaddr, socklen_t *addrlen); Returns:nonnegative descriptor if OK, -1 on error => return the next completed connection from the front of the completed connection queue. If queue is empty, the process is put to sleep.
  • 70. Return three values:1. integer return code2. protocol address of the client process3. size of this address : This integer value contains the actual number of bytes stored by the kernel in the socket address structure.If we are not interested in having the protocol address of theclient returned, we set both cliaddr and addrlen to nullpointers.
  • 71. fork and exec function#include <unistd.h> pid_t fork(void); Returns: 0 in child, process ID of child in parent, -1 on error#include <unistd.h>int execl(const char *pathname, const char *arg(), …/*(char *) 0*/);int execv(const char *pathname, char *const argv[]);int execle(const char *pathname, const char *arg());int execve(const char *pathname, char *const argv[], char *const envp[]);int execlp(const char *filename, const char *arg());int execvp(const char *filename, char *const argv[]); All six return: -1 on error, no return on success
  • 72. A process makes a copy of itself so that one copy can handle one operation while the other copy does another task.A process wants to execute another program. Since the only way to create a new process is by calling fork, the process first calls fork to make a copy of itself, and then one of the copies (typically the child process) calls exec to replace itself with the new program.
  • 73. The differences in the six exec functions are:(a) whether the program file to execute is specified by a filename or a pathname;(b) whether the arguments to the new program are listed one by one or referenced through an array of pointers; and(c) Whether the environment of the calling process is passed to the new program or whether a new environment is specified.
  • 74. Concurrent serverpid_t pidint listenfd, connfd;listenfd = Socket(...);//fill in sockaddr_in{} with server’s well-known portBind(listenfd, LISTENQ);for(;;){ connfd = Accept(listenfd, ...); if( (pid = Fork()) == 0) { Close(listenfd); /* child closes listening socket */ doit(connfd); //process the request Close(); //done with this client exit(0); //child terminate }Close(connfd); // parent close connected socket
  • 75. closeWhen finished using a socket, the socket should be closed:status = close(s); status: 0 if successful, -1 if error s: the file descriptor (socket being closed)Closing a socket closes a connection (for SOCK_STREAM) frees up the port used by the socket
  • 76. Return the address family of socket#include "unp.h" int sockfd_to_family(int sockfd){ struct sockaddr_storage ss; socklen_t len; len = sizeof(ss); if (getsockname(sockfd, (SA *) &ss, &len) < 0) return (-1); return (ss.ss_family);}
  • 77. getsockname and getpeernamefunction#include<sys/socket.h>int getsockname(int sockfd, struct sockaddr *localaddr, socklen_t *addrlen);int getpeername(int sockfd, struct sockaddr *peeraddr, socklen_t *addrlen); both return : 0 if OK, -1 on error=>getsockname : return local address associated with a socket getpeername : foreign protocol address associated with a socket
  • 78. getsockname and getpeernameThis function takes the following three input arguments:1. The sockets to query for the socket address.2. The pointer to the receiving buffer (argument name).3. Pointer to the maximum length variable. This variable provides the maximum length in bytes that can be received in the buffer (argument namelen).
  • 79. Reasons:TCP client that does not call bind, getsockname returns the local protocol addressAfter calling bind with a port no. of 0, getsockname returns the local port numberIt can be called to obtain the address family of a socket.Server binds to wildcard IP address,getsockname used to obtain the local protocol addressOnly way to obtain the identity of client is to call getpeername
  • 80. Value-result Argumentswhen a socket address structure is passed to any socket function, it is always passed by reference.That is, a pointer to the structure is passed. The length of the structure is also passed as an argument. But the way in which the length is passed depends on which direction the structure is being passed: from the process to the kernel, or vice versa.Bind, connect, and sendto pass socket address structure from the process to kernel
  • 81. Files to be createdClient STRING Server Client ServerClient source file - client.cServer source file - server.cHeader file - header.h
  • 82. TCP Echo Client/Server The client reads a line of text from its standard input and writes the line to the server. The server reads the line from its network input and echoes the line back to the client. The client reads the echoed line and prints it on its standard output.
  • 83. TCP Echo Server: main FunctionCreate socket, bind servers well-known portWait for client connection to completeConcurrent serverH:echo_server.cHeader file : unp.h
  • 84. TCP echo client.Create socket, fill in Internet socket address structureConnect to serverG:echo_client.c.txt
  • 85. TCP Echo Client: str_cliFunctionRead a line, write to serverRead echoed line from server, write to standard outputReturn to main