DOC PREVIEW
Princeton COS 217 - Client-Server Model

This preview shows page 1-2 out of 5 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1Client-Server ModelServer(file server,mail server, web server)NetworkNetworkPassive participantWaiting to be contactedClientWeb browserEmailerApplicationsActive participantInitiate contacts2Message Passing• Mechanism to pass data between two processes Sender sends a message from its memory Receiver receives the message and places it into its memory• Message passing is like using a telephone Caller Receiver3Network SubsystemApplication programTCP or UDPIPDevice DriverNICUserLevelKernelLevelHWSocket APIReliable data streamor unreliable data gramsRoutes through the internetTransmit or receive on LANNetwork interface card4Names and Addresses• Host name like a post office name; e.g., www.cs.princeton.edu• Host address like a zip code; e.g., 128.112.92.191• Port number like a mailbox; e.g., 0-64k5Socket• Socket abstraction An end-point of network connection Treat like a file descriptor• Conceptually like a telephone Connect to the end of a phone plug You can speak to it and listen to itNetworkNetwork6Steps for Client and ServerClient• Create a socket with the socket() system call • Connect the socket to the address of the server using the connect() system call • Send and receive data, using write() and read() system calls or send() and recv() system calls Server • Create a socket with the socket() system call • Bind the socket to an address using the bind() system call. For a server socket on the Internet, an address consists of a port number on the host machine. • Listen for connections with the listen() system call • Accept a connection with the accept() system call. This call typically blocks until a client connects with the server. • Send and receive data 7client.c (part 1)8client.c (part 2)9server.c (part 1)10server.c (part 2)11Creating A Socket (Install A Phone)• Creating a socket#include <sys/types.h>#include <sys/socket.h>int socket(int domain, int type, int protocol)– Domain: PF_INET (Internet), PF_UNIX (local)– Type: SOCK_STREAM, SOCK_DGRAM, SOCK_RAW– Protocol: 0 usually for IP (see /etc/protocols for details)• Like installing a phone Need to what services you want– Local or long distance– Voice or data– Which company do you want to use12Connecting To A Socket• Active open a socket (like dialing a phone number)int connect(int socket, struct sockaddr *addr, int addr_len)13Binding A Socket• Need to give the created socket an address to listen to(like getting a phone number)int bind(int socket,struct sockaddr *addr, int addr_len)– Passive open on a serverserver.c14Specifying Queued Connections• Queue connection requests (like “call waiting”)int listen(int socket, int backlog)– Set up the maximum number of requests that will be queued before being denied (usually the max is 5)server.c15Accepting A Socket• Wait for a call to a socket (picking up a phone when it rings)int accept(int socket, struct sockaddr *addr, int addr_len)– Return a socket which is connected to the caller– Typically blocks until the client connects to the socketserver.c16Sending Data• Sending a messageint send(int socket, char *buf, int blen, int flags)client.c17Receiving Data• Receiving a messageint recv(int socket, char *buf, int blen, int flags)server.c18Close A Socket• Done with a socket (like hanging up the phone)close(int socket)• Treat it just like a file descriptor19Summary• Pipes Process communication on the same machine Connecting processes with stdin and stdout• Messages Process communication across machines Socket is a common communication channels They are built on top of basic communication


View Full Document

Princeton COS 217 - Client-Server Model

Documents in this Course
Summary

Summary

4 pages

Lecture

Lecture

4 pages

Generics

Generics

14 pages

Generics

Generics

16 pages

Lecture

Lecture

20 pages

Debugging

Debugging

35 pages

Types

Types

7 pages

Lecture

Lecture

21 pages

Assembler

Assembler

16 pages

Lecture

Lecture

20 pages

Lecture

Lecture

39 pages

Testing

Testing

44 pages

Pipeline

Pipeline

19 pages

Lecture

Lecture

6 pages

Signals

Signals

67 pages

Building

Building

17 pages

Lecture

Lecture

7 pages

Modules

Modules

12 pages

Generics

Generics

16 pages

Testing

Testing

22 pages

Signals

Signals

34 pages

Lecture

Lecture

19 pages

Load more
Download Client-Server Model
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Client-Server Model and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Client-Server Model 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?