Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 27 Socket API Interface The interface between an application program and the communication protocols in an operating system is known as the Application.

Similar presentations


Presentation on theme: "Chapter 27 Socket API Interface The interface between an application program and the communication protocols in an operating system is known as the Application."— Presentation transcript:

1 Chapter 27 Socket API Interface The interface between an application program and the communication protocols in an operating system is known as the Application Program Interface (API). Programmers build network-aware programs tailored to a particular set of APIs (eg. NetBIOS, WinSock, or Novell Sockets) – NetBIOS is Microsoft’s native network API – WinSock is a network API that runs on top of TCP/IP on PCs. The socket API is an industry standard used on many operating systems such as Windows 2000 Windows NT, and Sun Solaris.

2 Sockets An abstraction through which an application may send and receive data via network to a remote application. Sockets provide a generic access to interprocess communication Sockets provide a method of identifying a specific server process running on a machine that is accessible via an IP connection.

3 Socket Types Sockets come in different flavors, corresponding to different underlying protocol families and different stacks of protocols within a family. The main flavors of sockets in TCP/IP family are stream sockets and datagram sockets. Stream (connection-oriented) sockets use TCP as the end- to-end protocol providing a reliable byte-stream service. Datagram (connectionless) sockets use UDP, providing a best-effort service. A socket using TCP/IP protocol familty is uniquely identified by an IP address, a port number, and a end-to- end protocol (eg. TCP or UDP). Until a socket is bound to a port number, it cannot receive messages from a remote application.

4 Socket API function calls Socket Connect Bind Listen Accept Close Send Recv Getpeername Gethostname Gethostbyname Gethostbyaddress

5 Socket Function Call socket procedure creates a socket and returns an integer descriptor: – descriptor = socket(protofamily, connection_type, protocol) – eg. socketdescriptor = socket(PF_INET, SOCK_STREAM, TCP) – eg. socketdescriptor = socket(PF_INET, SOCK_DGRAM, UDP)

6 TCP Socket Structure Send Queue Receive Queue Protocol state (eg. Closed, listening, established, connecting) Local port number Local IP Remote port number Remote IP Socket descriptor

7 Close Function Call close procedure tells the system to terminate the use of a socket. – Close(socket) – where socket is the descriptor for the socket being closed

8 Bind Function Call bind procedure is used to associate a socket to a particular protocol port number bind(socket, localaddr,addrlen) – Where localaddr references a sockaddr_in data structure containing TCP port# and IP address of computer

9 Listen Function Call listen procedure is used by a server to instruct the operating system to place a socket in passive mode so that it can wait for contact from clients. Listen(socket, queuesize)

10 Accept Function Call accept procedure is used by connection oriented server to accept the next connection request by creating a new socket. The server’s original socket remains unchanged and is used to accept the next connection from a client. newsock=accept(socket, client_address, client_address_length) – Where client_address points to a sockaddr structure containing TCP port# and IP address of client computer – The new socket listens to the same port by forking a new process

11 Connect Function Call connect procedure is used by clients to establish a connection with a specific server. – When used with connection-oriented transport, connect establishes a transport connection to a specified server. – When used with connectionless transport, connect records the server’s address in the socket, allowing the client to send many messages to the same server without repeatedly specifying the server address with each message. connect (socket, server_IPaddress_and_port_number, server_address_length)

12 Send Function Call Send procedure is used by both clients and servers to send request and response via a connected socket. Send (socket, data, length, flags) – Where data is address of data buffer

13 Recv Function Call Recv procedure is used by both clients and servers to receive data sent by the other via a connected socket. Recv(socket, buffer, length, flags) – Where buffer contains data sent by other computer

14 Other function calls Getpeername procedure is used by server to obtain the address of the client that initiated the connection Gethostname procedure is used by both server and client to obtain name of of computer on which it is running. Gethostbyname procedure is usually used by clients to translate a hostname into an IP address. Gethostbyaddress is used by clients and servers to translate an IP address to a hostname.

15 Server and Client Socket Function Calls Server socket calls: – socket, bind, listen, accept, recv, getpeername, gethostbyaddr, send, close Client socket calls: – socket, connect, send, recv, close

16 Socket Function Calls socket bind listen accept send/recv close socket connect Recv/send close Server Client


Download ppt "Chapter 27 Socket API Interface The interface between an application program and the communication protocols in an operating system is known as the Application."

Similar presentations


Ads by Google