communication
play

Communication Karens Home Page - Courses -kites Sockets (Haviland - PDF document

Simple Web Request Communication Karens Home Page - Courses -kites Sockets (Haviland Ch. 10) Domain Name Servers This is getting complicated! 128.100.10.235 browser 128.100.10.235 browser server www.eecg. eecg utoronto.ca?


  1. Simple Web Request Communication Karen’s Home Page - Courses -kites Sockets (Haviland – Ch. 10) Domain Name Servers This is getting complicated! 128.100.10.235 browser 128.100.10.235 browser server www.eecg. “eecg” utoronto.ca? name server local www.eecg. name server eecg www.eecg. utoronto.ca? “eecg” server www.eecg. name server utoronto.ca? local utoronto.ca? name server “utoronto” ca utoronto name server root server “utoronto” server name server name server root “ca” name server www.eecg. “ca” name server utoronto.ca? name server 1

  2. Routing Putting it together dis17-toronto64- dis17-toronto64- fe10.bellnexxia.net fe10.bellnexxia.net onet-gw.dis1-toronto. bellnexxia.net onet-gw.dis1-toronto. browser HSE-Toronto- bellnexxia.net ppp.sympatico.ca HSE-Toronto- dis1-toronto-64- utorgw-border-if. pos2.bellnexxia.net ppp.sympatico.ca onet.on.ca dis1-toronto-64- utorgw-border-if. pos2.bellnexxia.net sf2-bbup.gw. onet.on.ca “eecg” utoronto.ca name server browser local name server sf2-bbup.gw. utoronto.ca “utoronto” name server server root name server server “ca” name server How do we find the server? IP addressing � IP address is 32 bits. � Every computer on the Internet has an Internet address. � In theory, it’s enough to identify 2^32 = 4 billion locations � Called an IP address (Internet Protocol) � In practice, it’s much less – routing needs � An IP address is 4 8-bit numbers separated � IP address is like a general road map. by dots. � Each part of the address provides more specific info. www.eecg.toronto.edu = 128.100.10.235 � Much like a regular address: country,city,street, street #, apt # 2

  3. IP address format Address classes � Class A: � In general it is of the form network.node � 1 bit of 0, 7 bits network #, 24 bits node number � Routing decisions make on network part � 126 possible class A addresses (0 reserved, � Network part is bigger (more networks, 127 is loopback), with 2^24 = 16,777,214 smaller # of nodes/network), or smaller (less nodes networks, big # of nodes/network) depending on the network class � given to very large organizations. Eg. ISPs � 5 classes: A, B, C, D and E Address Classes Cont’d Address Classes Cont’d � Class B: 2 bits of 10, 14 bits of network #, 16 � Class C: 3 bits of 110, 21 bits of network #, 8 bits of node # bits of node # � 2^14 possible class B addresses, with 2^16 = � 2^21 = 2,097,150 class C addresses, with 65,534 nodes. 254 nodes each � Nearly depleted. Given to large institutions � Class D: 224.0.0.0 to 239.255.255.255 – like universities reserved � Class E: 240.0.0.0 to 255.255.255.255 – reserved 3

  4. Routing Challenges to network communication � Dynamic connections � Each network keeps track of 1 st hop on the � Network connections appear and disappear route to all other networks � Messages may take different paths, so arrival sequence not guaranteed. � Knows which gateway to use for each other � Data loss network � May drop/corrupt bits through unreliable � “Store and forward” approach connection � Constricted paths � Different machines/technologies have differing limits on packet size. A large packet may have problems Protocols Protocols � Knowing how to find someone to deliver a Invoice: Customer: Karen Reid Karen Reid Feb 18, 2001 Order No: 5379 message is not enough Payable to: CPUS are us $596.74 Qty: Unit Price Total Five hundred ninety six 74/100 � Need a set of rules to effectively 1 Athalon 219.00 219.00 2 128 MB 149.95 299.90 ____________ Subtotal 518.90 communicate Tax 77.84 TOTAL 596.74 � A protocol is an agreed upon way of doing Karen Reid things CPUS are us CPUS are us 0 College Street Karen Reid Toronto Ontario M5S 3G4 � Many examples of protocols in real life: Dept. of Computer Science University of Toronto Morse code, We deliver! � TCP, UDP, IP Courier 4

  5. Connection oriented vs. connectionless IP as a protocol � Data to be sent is divided into packets � Connection oriented (a.k.a) virtual circuit is like a telephone connection. � A packet has at least 3 basic elements: source, destination, and data � Send unformatted, uninterrupted stream of � Can always identify where a packet came from, characters to the same location where it’s going, and how big it is � TCP � Does not guarantee arrival of packet at destination. � Connectionless model is like mail – you aren’t Nor does it guarantee the ordering of arrival. sure if it got there � But if a packet arrives, then its integrity is � Good for broadcast messages guaranteed � UDP UDP – a connectionless protocol TCP – transmission control protocol � UDP = user datagram protocol � Built on top of IP (Hence TCP/IP) � A.K.A. Unreliable datagram protocol ☺ � Connection oriented � Built on top of IP � Guarantees delivery � Low overhead � Adds sequencing and acknowledgement info to each packet � No guarantee of delivery � Cooperates to ensure data stream received is � Good for broadcast messages reconstructed in the same sequence as the original 5

  6. TCP Connection Sockets 3-way handshake SYN Hi 128.100.10.25 � One form of communication between Hi 128.100.10.128 Connection port 1? Let’s talk processes. okay � Similar to pipes, except sockets can be used between processes on different machines. Send me a file Here’s some data � Use file descriptors to refer to sockets. Got it ack Here’s some more � Built on top of TCP layer Got it ack fin I’m done fin I’m done too Socket Types Addresses and Ports try nslookup � A socket pair is the two endpoints of the � Two main categories of sockets connection. � UNIX domain: both processes on the same � An endpoint is identified by an IP address machine and a port. � INET domain: processes on different machines � IPv4 addresses are 4 8-bit numbers: � Three main types of sockets: � 128.100.31.156 = penguin � SOCK_STREAM: the one we will use � 128.100.31.4 = eddie � SOCK_DGRAM: for connectionless sockets � Ports � SOCK_RAW � because multiple processes can communicate with a single machine we need another identifier. 6

  7. More on Ports Connection-Oriented www.iana.org � Well-known ports: 0-1023 Server � 80 = web � 21 = ftp � Create a socket: socket() � 25 = smtp (mail) � 22 = ssh � Assign a name to a socket: bind() � 194 = irc � 23 = telnet � Establish a queue for connections: listen() � Registered ports: 1024-49151 � Get a connection from the queue: accept() � 2709 = supermon Client � 26000 = quake � Dynamic (private) ports: 49152-65535 � Create a socket: socket() � You should pick ports in this range to avoid � Initiate a connection: connect() overlap Server side Code thus far (server and client) #include <ctypes.h> #include <sys/types.h> int socket(int family, int type, #include <sys/socket.h> #include <netinet/in.h> int protocol); � family specifies protocol family: int main(void) { � AF_INET – Internet domain for networking int sockfd; � AF_UNIX – Unix domain (process on the same machine) if((sockfd=socket(AF_INET,SOCK_STREAM,0))==-1) � type { //handle error, quit � SOCK_STREAM, SOCK_DGRAM } � protocol //server: bind, listen for incoming connections, accept //connections � set to 0 except for RAW sockets //client: connect to the server, start send & receive � returns a socket descriptor 7

  8. bind to a name Set up queue in kernel int bind(int sockfd, const struct sockaddr *servaddr, int listen(int sockfd, int backlog) socklen_t addrlen); Associates the network address of a machine with a socket � after calling listen , a socket is ready to � sockfd – returned by socket � accept connections struct sockaddr_in{ � sa_family sin_family; /*AF_INET */ � prepares a queue in the kernel where in_port sin_port; struct in_addr sin_addr; partially completed connections wait to be unsigned char sin_zero[8]; accepted. } sin_addr can be set to INADDR_ANY to communicate with any � � backlog is the maximum number of partially host Set sin_addr like so: completed connections that the kernel should � .sin_addr.s_addr=inet_addr(“197.124.10.1”); queue. Code (server side): Complete the connection //... Call socket() int accept(int sockfd, #define SIZE sizeof(struct sockaddr_in) struct sockaddr *cliaddr, struct sockaddr_in server; socklen_t *addrlen); if( bind(sockfd,(struct sockaddr*)&server,SIZE)==-1) { � blocks waiting for a connection (from the queue) //handle error, quit � returns a new descriptor which refers to the TCP } //start listening for connections connection with the client if( listen(sockfd,5) == -1) � sockfd is the listening socket { � cliaddr is the address of the client //handle error, quit } � reads and writes on the connection will use the // todo: accept a connection, spawn child to deal socket returned by accept // with the connection 8

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