
The OS finds a port each time the sends a pkt if receiving, need to bind SOCK_STREAM: destination determined during conn. When and why? Recall: no connection setup for SOCK_DGRAM A connection occurs between two kinds of participants passive: waits for an active participant to request connection active: initiates connection request to passive side Once connection is established, passive and active participants are similar both can send & receive data either can terminate the connection 9 11 Skipping the bind Connection setup cont d SOCK_DGRAM: if only sending, no need to bind. App D1 D2 2 Q: why have type SOCK_DGRAM? D3 4Ģ Socket Creation in C: int s = (domain, type, protocol) s: descriptor, an integer (like a file-handle) domain: integer, communication domain e.g., PF_INET (IPv4 protocol) typically used type: communication type SOCK_STREAM: reliable, 2-way, connection-based service SOCK_DGRAM: unreliable, connectionless, other values: need root permission, rarely used, or obsolete protocol: specifies protocol (see file /etc/protocols for a list of options) - usually set to 0 NOTE: call does not specify where data will be coming from, nor where it will be going to it just creates the interface! Ports Each host has 65,536 ports Some ports are reserved for specific apps Port 0 Port 1 Port ,21: FTP! A provides an interface 23: Telnet to send data to/from the 80: HTTP network through a port see RFC 1700 (about 2000 ports are reserved) 5 7 A Socket-eye view of the Internet soorma.cs. ( ) cluster.cs. (, ,, ) newworld.cs. ( ) Addresses, Ports and Sockets Like apartments and mailboxes You are the application Your apartment building address is the address Your mailbox is the port The post-office is the network The is the key that gives you access to the right mailbox (one difference: assume outgoing mail is placed by you in your mailbox) Each host machine has an IP address When a packet arrives at a host Q: How do you choose which port a connects to? 6 8ģ The bind function Connection Setup (SOCK_STREAM) associates and (can exclusively) reserves a port for use by the int status = bind(sockid, &addrport, size) status: error status, = -1 if bind failed sockid: integer, descriptor addrport: struct sockaddr, the (IP) address and port of the machine (address usually set to INADDR_ANY chooses a local address) size: the size (in bytes) of the addrport structure bind can be skipped for both types of s. for each packet can send or receive We will look at using s in C For Java, see Chapter (optional) Note: Java s are conceptually quite similar Dest. UDP unreliable delivery no order guarantees no notion of connection app indicates dest. TCP reliable delivery in-order guaranteed connection-oriented bidirectional App SOCK_DGRAM a.k.a. connectionless Once configured the application can pass data to the for network transmission receive data from the (transmitted through the network by some other host) 1 3 Socket Programming What is a? Using s Types (Protocols) Associated functions Styles Two essential types of s SOCK_STREAM a.k.a. 1 What is a? Last Year s COMS 4119 Computer Networking Socket Programming Vishal Misra Department of Computer Science An interface between application and network The application creates a The type dictates the style of communication reliable vs.
