services
play

Services Do A for me. Sockets and Client/Server OK, heres your - PDF document

Services Do A for me. Sockets and Client/Server OK, heres your answer. Communication Now do B. OK, here. Client Server Jeff Chase request/response paradigm ==> client/server roles Duke University - Remote


  1. Services “Do A for me.” Sockets and Client/Server “OK, here’s your answer.” Communication “ Now do B.” “OK, here.” Client Server Jeff Chase request/response paradigm ==> client/server roles Duke University - Remote Procedure Call (RPC) - object invocation, e.g., Remote Method Invocation (RMI) - HTTP (the Web) - device protocols (e.g., SCSI) Networking Basics An Internet Application • Applications Layer – Standard apps Internet client host Internet server host • HTTP • FTP Client User code Server Application • Telnet Sockets interface – User apps (http,ftp,telnet,…) (system calls) • Transport Layer Transport TCP/IP Kernel code TCP/IP – TCP (TCP, UDP,..) – UDP Hardware interface Network (interrupts) – Programming Interface: Network Hardware Network (IP,..) • Sockets and firmware adapter adapter • Network Layer Link – IP (device driver,..) • Link Layer Global IP Internet – Device drivers [Buyya] [CMU 15-213] A Programmer’s View of the Internet Internet Connections • Most clients and servers communicate by sending streams of • Hosts are mapped to a set of 32-bit IP addresses . bytes over connections – E.g., using TCP, the Transmission Control Protocol – 128.2.203.179 • A socket is an endpoint of a connection between two processes. – Unix and Windows system calls, Java APIs • The set of IP addresses is mapped to a set of identifiers called Internet domain names . socket socket – 128.2.203.179 is mapped to www.cs.cmu.edu • A process on one Internet host can communicate with Client Server TCP byte-stream connection a process on another Internet host over a connection. (128.2.194.242, 208.216.181.15) Client host address Server host address 128.2.194.242 208.216.181.15 [CMU 15-213] [adapted from CMU 15-213] 1

  2. Sockets: the rest of the story Using Ports to Identify Services Server host 128.2.194.242 • A host might have many open connections, possibly held by different processes. Client host Service request for Web server 128.2.194.242:80 (port 80) • A port is a unique communication endpoint on a host, (i.e., the Web server) Kernel named by a 16-bit integer, and associated with a process. Client (connect request) Echo server (port 7) Client socket address Server socket address 128.2.194.242:51213 208.216.181.15:80 Server Client (port 80) Connection socket pair Service request for Web server (128.2.194.242:51213, 208.216.181.15:80) 128.2.194.242:7 (port 80) (i.e., the echo server) Client host address Server host address Kernel Client 128.2.194.242 208.216.181.15 (connect request) Echo server Note: 80 is a well-known port (port 7) Note: 51213 is an associated with Web servers ephemeral port allocated by the kernel [CMU 15-213] [CMU 15-213] More on Ports Berkeley Sockets • This port abstraction is an Internet Protocol concept. • Networking protocols are implemented as part of the – Source/dest port is named in every packet. OS – Kernel looks at port to demultiplex incoming traffic. – The networking API exported by most OS’s is the • The term is commonly used to refer to a communication socket interface endpoint in other contexts. – Originally provided by BSD 4.1c ~1982. • How do clients know what port number to connect to? • The principal abstraction is a socket – We have to agree on well-known ports for common – Point at which an application attaches to the services: ICAAN again network – Look at /etc/services – Defines operations for creating connections, – Ports 1023 and below are ‘reserved’ attaching to network, sending/receiving data, • Clients need a return port, but it can be an ephemeral closing. port assigned dynamically by the kernel. [Paul Barford] Datagrams and Streams Unix Sockets I • Creating a socket Communication over the Internet uses a selected transport-layer protocol (layer 4) built above the common IP packet protocol. int socket(int domain, int type, int protocol) • Point-to-point communication with a socket/port at either end. • domain = AF_INET, AF_UNIX • UDP = User Datagram Protocol (AF_INET/SOCK_DGRAM) • type = SOCK_STREAM, SOCK_DGRAM – Send/receive messages up to 8KB (plus) – Unreliable: messages may be lost or reordered – Connectionless: no notion or cost of ‘establishing a connection’ • TCP = Transmission Control Protocol (AF_INET/SOCK_STREAM) – Send/receive byte streams of arbitrary length (like a pipe) What is this – All bytes delivered are correct and delivered in order integer that is – Masks transient packet loss returned? – Connection setup/maintenance: other end is notified if one end closes or resets the connection, or if the connection breaks. 2

  3. Sending/Receiving Unix File Descriptors Illustrated • Use read/write system calls and variants to user space kernel transmit/receive byte-stream data. file – “Just like files”! pipe – Close works too • Alternative syscalls for sending/receiving messages process file descriptor socket • Variants of: table system open file int send(int socket, char *msg, int mlen, int flags) tty table File descriptors are a special int recv(int socket, char *buf, int blen, int flags) case of kernel object handles . The binding of file descriptors to objects is Disclaimer: specific to each process, like the virtual this drawing is translations in the virtual address space. oversimplified. Listening for a Connection Making a Connection • If everything goes well, the server accepts the • A server (program) runs on a specific computer and connection. has a socket that is bound to a specific port. The • Upon acceptance, the server gets a new socket bound server waits and listens to the socket for a client to to a different port. make a connection request. – It needs a new socket (consequently a different port number) so that it can continue to listen to the original socket for connection requests while serving the connected client. port server port Connection request port Client server port Client Connection [Buyya] [Buyya] Server-Side Sockets Client Socket • Bind socket to IP address/port • Active Open (on client) int bind(int socket, struct sockaddr *addr, int addr_len) int connect(int socket, struct sockaddr *addr, • Mark the socket as accepting connections int addr_len) int listen(int socket, int backlog) • “Passive open” accepts connection int accept(int socket, struct sockaddr *addr, int addr_len) (returns a new socket to talk to the client) 3

  4. Connection-oriented example Connectionless example (TCP) (UDP) Server Server Socket() Socket() Client Bind() Bind() Socket() Client Listen() Recvfrom() Bind() Socket() Block until Accept() Sendto() Connection Establishmt. Connect() Data from Block until Data (request) client connect Data (request) Send() Recv() Process Process request request Data (reply) Data (reply) Send() Sendto() Recv() Recvfrom() [Paul Barford] [Paul Barford] Socket call Bind call • Means by which an application attached to the network • Binds a newly created socket to the specified address • int socket(int family, int type, int protocol) • Int bind(int socket, struct sockaddr *address, int addr_len) • Family : address family (protocol family) • Socket : newly created socket handle – AF_UNIX, AF_INET, AF_NS, AF_IMPLINK • Type : semantics of communication • Address : data structure of address of local system – SOCK_STREAM, SOCK_DGRAM, SOCK_RAW – IP address and port number (demux keys) – Not all combinations of family and type are valid – Same operation for both connection-oriented and • Protocol : Usually set to 0 but can be set to specific value. connectionless servers – Family and type usually imply the protocol • Can use well known port or unique port • Return value is a handle for new socket [Paul Barford] [Paul Barford] Listen call Accept call • Used by connection-oriented servers to indicate an application is willing to receive connections • After executing listen, the accept call carries out a passive open (server prepared to accept connects). • Int(int socket, int backlog) • Int accept(int socket, struct sockaddr *address, int addr_len) • Socket : handle of newly creates socket • It blocks until a remote client carries out a • Backlog : number of connection requests that can be connection request. queued by the system while waiting for server to • When it does return, it returns with a new socket execute accept call. that corresponds with new connection and the address contains the clients address [Paul Barford] [Paul Barford] 4

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend