Harvey Mudd CS 105 - Network Programming

Unformatted text preview:

Network ProgrammingClient-Server TransactionsProgrammer’s View of Internet1. IP Addresses2. Domain Naming System (DNS)3. Internet ConnectionsClientsUsing Ports to Identify ServicesServersServer ExamplesSockets InterfaceOverview of Sockets InterfaceSocketsSocket Address StructuresEcho Client Main RoutineEcho Client: open_clientfdEcho Client: open_clientfd (getaddrinfo)Echo Client: open_clientfd (socket)Echo Client: open_clientfd (connect)Echo Server: Main RoutineEcho Server: open_listenfdEcho Server: open_listenfd (getaddrinfo)Echo Server: open_listenfd (socket)Echo Server: open_listenfd (setsockopt)Echo Server: open_listenfd (bind)Echo Server: open_listenfd (listen)Echo Server: Main LoopEcho Server: acceptEcho Server: accept IllustratedConnected vs. Listening DescriptorsEcho Server: Identifying ClientEcho Server: echoTesting Servers Using telnetTesting Echo Server With telnetRunning Echo Client and ServerOne More Important FunctionFor More InformationNetwork ProgrammingNetwork ProgrammingTopicsTopicsProgrammer’s view of the Internet (review)Sockets interfaceWriting clients and serversCS 105“Tour of the Black Holes of Computing!”– 2 –CS 105Client-Server TransactionsClient-Server TransactionsClientprocessServerprocess1. Client sends request2. Server handlesrequest3. Server sends response4. Client handlesresponseResourceEvery network application is based on client-server Every network application is based on client-server model:model:Server process and one or more client processesServer manages some resource.Server provides service by manipulating resource for clientsNote: clients and servers are processes running on hosts (can be the same or different hosts)– 3 –CS 105Programmer’s View of InternetProgrammer’s View of Internet1. Hosts are mapped to set of 32-bit or 128-bit 1. Hosts are mapped to set of 32-bit or 128-bit IP IP addressesaddresses134.173.42.22001:1878:301:902:214:22ff:fe7c:883f2. IP addresses are mapped to identifiers called Internet 2. IP addresses are mapped to identifiers called Internet domain namesdomain names134.173.42.2 maps to www.cs.hmc.edu In general, mapping is many-to-many3. Process on one Internet host can communicate with 3. Process on one Internet host can communicate with process on another over a process on another over a connectionconnection– 4 –CS 1051. IP Addresses1. IP AddressesComputers are identified by Computers are identified by IP addressesIP addressesTwo flavors: IPv4 (old) and IPv6 (new)Two flavors: IPv4 (old) and IPv6 (new)Both are stored in an Both are stored in an IP address struct IP address struct of appropriate of appropriate typetypein_addr for IPv4in6_addr for IPv6Details don’t matter; library functions usually hide themDetails don’t matter; library functions usually hide them– 5 –CS 1052. Domain Naming System (DNS)2. Domain Naming System (DNS)Internet maintains mapping between IP addresses and Internet maintains mapping between IP addresses and domain names in huge worldwide distributed database domain names in huge worldwide distributed database called called DNSDNSConceptually, programmers can view DNS database as collection of millions of host entry structures:Functions for retrieving host entries from DNS:Functions for retrieving host entries from DNS:getaddrinfo: query key is a DNS domain namegetnameinfo: query key is an IP address/* DNS host entry structure */ struct hostent { char *h_name; /* official domain name of host */ char **h_aliases; /* null-terminated array of domain names */ int h_addrtype; /* host address type (AF_INET or AF_INET6) */ int h_length; /* length of an address, in bytes */ char **h_addr_list; /* null-terminated array of in*_addr structs */ };– 6 –CS 1053. Internet Connections3. Internet ConnectionsConnection socket pair(128.2.194.242:51213, 134.173.42.2:80)Server(port 80)ClientClient socket address128.2.194.242:51213Server socket address134.173.42.2:80Client host address128.2.194.242 Server host address134.173.42.2Clients and servers communicate by sending streams Clients and servers communicate by sending streams of bytes over of bytes over connectionsconnectionsConnections are point-to-point, full-duplex (2-way Connections are point-to-point, full-duplex (2-way communication), and reliablecommunication), and reliableNote: 51213 is anephemeral port allocatedby the kernel Note: 80 is a well-known portassociated with Web servers– 7 –CS 105ClientsClientsExamples of client programsExamples of client programsWeb browsers, ftp, telnet, sshHow does a client find the server?How does a client find the server?IP address in server socket address identifies host (more precisely, an adapter on the host)(Well-known) port in server socket address identifies service, and thus implicitly identifies server process that provides itExamples of well-known portsPort 7: Echo serverPort 23: Telnet serverPort 25: Mail serverPort 80: Web server– 8 –CS 105Using Ports to Identify ServicesUsing Ports to Identify ServicesWeb server(port 80)Client hostServer host 134.173.42.2Echo server(port 7)Service request for134.173.42.2:80(i.e., Web server)Web server(port 80)Echo server(port 7)Service request for134.173.42.2:7(i.e., echo server)KernelKernelClientClient– 9 –CS 105ServersServersServers are long-running processes (daemons).Servers are long-running processes (daemons).Created at boot time (typically) by init process (process 1)Run continuously until machine is turned offOr spawned by inetd in response to connection to portEach server waits for requests to arrive on well-known Each server waits for requests to arrive on well-known port associated with that particular serviceport associated with that particular servicePort 7: echo serverPort 22: ssh serverPort 25: mail serverPort 80: HTTP serverMachine that runs a server process is also often referred Machine that runs a server process is also often referred to as a “server”to as a “server”– 10 –CS 105Server ExamplesServer ExamplesWeb server (port 80)Web server (port 80)Resource: files/compute cycles (CGI programs)Service: retrieves files and runs CGI programs on behalf of the clientFTP server (20, 21)FTP server (20, 21)Resource: filesService: stores and retrieve filesSsh server (22)Ssh server (22)Resource: terminalService: proxies a terminal on the server machineMail


View Full Document

Harvey Mudd CS 105 - Network Programming

Documents in this Course
Processes

Processes

25 pages

Processes

Processes

27 pages

Load more
Download Network Programming
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 Network Programming 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 Network Programming 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?