You are on page 1of 5

Example: Java client (TCP) import java.io.*; import java.net.

*; class TCPClient { public static void main(String argv[]) throws Exception { String sentence; String modifiedSentence; BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); Socket clientSocket = new Socket("hostname", 6789); DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream()); BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); sentence = inFromUser.readLine(); outToServer.writeBytes(sentence + '\n'); modifiedSentence = inFromServer.readLine(); System.out.println("FROM SERVER: " + modifiedSentence); clientSocket.close(); } } Example: Java server (TCP) import java.io.*; import java.net.*; class TCPServer { public static void main(String argv[]) throws Exception { String clientSentence; String capitalizedSentence; ServerSocket welcomeSocket = new ServerSocket(6789); while(true) { Socket connectionSocket = welcomeSocket.accept(); BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream())); DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream()); clientSentence = inFromClient.readLine(); capitalizedSentence = clientSentence.toUpperCase() + '\n';

outToClient.writeBytes(capitalizedSentence); } } } Example: Java client (UDP) import java.io.*; import java.net.*; class UDPClient { public static void main(String args[]) throws Exception { BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); DatagramSocket clientSocket = new DatagramSocket(); InetAddress IPAddress = InetAddress.getByName("hostname"); byte[] sendData = new byte[1024]; byte[] receiveData = new byte[1024]; String sentence = inFromUser.readLine(); sendData = sentence.getBytes(); DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876); clientSocket.send(sendPacket); DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); clientSocket.receive(receivePacket); String modifiedSentence = new String(receivePacket.getData()); System.out.println("FROM SERVER:" + modifiedSentence); clientSocket.close(); } }

HTTP uses persistent connections in default mode. HTTP methods (HTTP/1.1) GET: browser requests an object identified in the URL POST:1) used when web page includes form input browser requests a Web page 2) contents of Web page depending on input to server in entity body HEAD: 1) asks server to leave requested object out of response 2) used for debugging purpose by application developers PUT: uploads object in entity body to path specified in URL field DELETE: deletes object specified in the URL field

HTTP response status code/phrase 200 OK !! request succeeded, requested object later in this message 301 Moved Permanently !! requested object moved, new location specified later in this message (Location: header field) 400 Bad Request !! request message not understood by server 404 Not Found !! requested document not found on this server 505 HTTP Version Not Supported HTTP as an example application protocol typical request/reply message exchange client requests info or service server responds with data, status code message formats headers: fields giving info about data data: info being communicated SMTP: simple mail transfer protocol: use TCP to reliably transfer mail message from senders mail server to recipients mail server (port 25) POP3: Post Office Protocol: user agents opens a TCP connection to its mail server (port 110) IMAP: Internet Mail Access Protocol: Keeps state information across sessions DNS: Domain Name System: over UDP (port 53) TCP: point-to-point: one sender, one receiver reliable data transfer: in-order byte stream full duplex service: bi-directional data flow in same connection connection-oriented: handshaking (exchange of control msgs) before data exchange flow and congestion controlled: sender will not overwhelm receiver; sender adjusts sending rate upon detecting congestion

TCP RDT: simplified sender NextSeqNum = InitialSeqNum SendBase = InitialSeqNum loop (forever) { switch(event) event: data received from application above create TCP segment with sequence number NextSeqNum if (timer currently not running) start timer pass segment to IP NextSeqNum = NextSeqNum + length(data) event: timer timeout retransmit not-yet-acknowledged segment with smallest sequence number start timer event: ACK received, with ACK field value of y if (y > SendBase) {

SendBase = y if (there are currently not-yet-acknowledged segments) start timer } } /* end of loop forever */ Congestion Control Approaches: end-to-end control: tcp network-assisted congestion control: routers provide feedback to end systems; ATM IPV6:

Expanded address space: 128 bits Fixed-length 40-byte header allows fast processing of IPV6 datagram no options field (but can be pointed to from next header field) Flow labeling and priority service differentiation among datagrams belonging to different flows no fragmentation/reassembly allowed at the routers can only be done at source/destination hosts to speed up IP forwarding no header checksum

IPV4->IPV6: Dual-stack approach: IPv6 routers also have a complete IPv4 implementation, with both an IPv4 address and an IPv6 address use IPv4 to communicate with IPv4 routers use IPv6 to communicate with IPv6 routers Tunneling: IPv6 carried as payload in IPv4 datagram among IPv4 routers Internet Control Message Protocol ICMP Used by hosts & routers to communicate network-layer information among each other error reporting unreachable host/network/port/protocol echo request, reply e.g., used in ping, traceroute ICMP message: type, code, checksum, data Above IP: ICMP messages carried inside IP datagrams LS link-state) algorithms used in OSPF. DV (distance-vector) algorithms used RIP, BGP. Dijkstras algorithm Bellman-Ford equation Intra-AS routing protocols (also known as Interior Gateway Protocols) RIP: Routing Information Protocol (DV) OSPF: Open Shortest Path First (LS) Others: IGRP: Interior Gateway Routing Protocol (Cisco proprietary) ( IS-IS: Intermediate System to Intermediate System (closely related to OSPF) Inter-AS routing protocol: BGP

Link-Layer Services: Framing: encapsulate datagram into frame, adding header, trailer Link access multiple access problem: how multiple nodes can share a single broadcast link Medium Access Control (MAC) protocols, or multiple access protocols: to solve the multiple access problems Reliable delivery between adjacent nodes: done by acknowledgement and retransmission (ARQ) used on links prone to high error rates, e.g., wireless links; seldom used on low bit-error link, e.g., fiber, coax, many twisted pair copper links Flow control: pacing between adjacent sending and receiving nodes nodes have limited frame buffering capacity prevent sending node from overwhelming receiving node Error detection: errors caused by signal attenuation, electromagnetic noise, etc. ; receiver detects presence of errors; drops frame or signals sender for retransmission Error correction: receiver may identify and correct bit error(s) without resorting to retransmission Half-duplex and full-duplex full duplex: nodes at both ends of link can transmit at same time half duplex: nodes at both ends of link can transmit, but not at same time CDMA: code division multiple access Examples of random access protocols: Aloha, CSMA, CSMA/CD Carrier Sense Multiple Access (CSMA): carrier sensing: listen before transmitting -> Human analogy: dont interrupt others! Collisions can still occur-> due to propagation delay, two nodes may not hear each others transmission in case of collision, node continues transmitting the entire frame in CSMA Carrier Sense Multiple Access with Collision Detection (CSMA/CD): collision detection: if other transmission detected, node aborts its current transmission Address Resolution Protocol: resolves IP address to MAC address for nodes in the same LAN CRC (Cyclic Redundancy Check Codes): 4 bytes CRC check: receiver computes CRC using all fields other than CRC, Preamble, and compare with whats carried in CRC field Channel efficiency of Ethernets CSMA/CD: efficiency = 1/(1+5d(drop)/d(trans))=>better performance than slotted ALOHA, and simple, cheap, decentralized! no CSMA/CD at hub: host NICs detect collisions and perform CSMA/CD Routers: network-layer devices (examine network-layer headers); not plug-and-play Switches: link-layer devices (examine link-layer headers); plug-and-play WiFi:all use CSMA/CA for multiple access; all have base-station and ad-hoc network versions DIFS: Distributed Inter-Frame Space SIFS: Short Inter-Frame Space

You might also like