Data Communication & Networks G22.2262-001



Similar documents
Network Programming using sockets

DNS: Domain Names. DNS: Domain Name System. DNS: Root name servers. DNS name servers

Socket programming. Socket Programming. Languages and Platforms. Sockets. Rohan Murty Hitesh Ballani. Last Modified: 2/8/2004 8:30:45 AM

Goal: learn how to build client/server application that communicate using sockets. An interface between application and network

Chapter 2: Application layer

Java Network. Slides prepared by : Farzana Rahman

Data Communications & Networks. Session 2 Main Theme Application Layer. Dr. Jean-Claude Franchitti

Transport Layer Services Mul9plexing/Demul9plexing. Transport Layer Services

String sentence = new String(receivePacket.getData()); InetAddress IPAddress = receivepacket.getaddress(); int port = receivepacket.

Internet Applications & Socket Programming

Socket Programming. Announcement. Lectures moved to

Transport layer protocols. Message destination: Socket +Port. Asynchronous vs. Synchronous. Operations of Request-Reply. Sockets

SSC - Communication and Networking Java Socket Programming (II)

Limi Kalita / (IJCSIT) International Journal of Computer Science and Information Technologies, Vol. 5 (3), 2014, Socket Programming

Network Communication

Division of Informatics, University of Edinburgh

Socket UDP. H. Fauconnier 1-1. M2-Internet Java

Lesson: All About Sockets

Chapter 11. User Datagram Protocol (UDP)

Network Programming TDC 561

The Transport Layer. Antonio Carzaniga. October 24, Faculty of Informatics University of Lugano Antonio Carzaniga

SIP: Session Initiation Protocol

Chapter 2: outline. 2.6 P2P applications 2.7 socket programming with UDP and TCP

NETWORK PROGRAMMING IN JAVA USING SOCKETS

Abstract Stream Socket Service

Learning Outcomes. Networking. Sockets. TCP/IP Networks. Hostnames and DNS TCP/IP

Application Development with TCP/IP. Brian S. Mitchell Drexel University

Socket Programming in Java

Names & Addresses. Names & Addresses. Hop-by-Hop Packet Forwarding. Longest-Prefix-Match Forwarding. Longest-Prefix-Match Forwarding

Question1-part2 What undesirable consequences might there be in having too long a DNS cache entry lifetime?

Java Programming: Sockets in Java

Mail User Agent Project

The exam has 110 possible points, 10 of which are extra credit. There is a Word Bank on Page 8. Pages 7-8 can be removed from the exam.

Socket-based Network Communication in J2SE and J2ME

Introduction to Socket programming using C

Network layer" 1DT066! Distributed Information Systems!! Chapter 4" Network Layer!! goals: "

IP Network Layer. Datagram ID FLAG Fragment Offset. IP Datagrams. IP Addresses. IP Addresses. CSCE 515: Computer Network Programming TCP/IP

ELEN 602: Computer Communications and Networking. Socket Programming Basics

Note! The problem set consists of two parts: Part I: The problem specifications pages Part II: The answer pages

Building a Multi-Threaded Web Server

Transport Layer. Chapter 3.4. Think about

Communicating with a Barco projector over network. Technical note

Network-Oriented Software Development. Course: CSc4360/CSc6360 Instructor: Dr. Beyah Sessions: M-W, 3:00 4:40pm Lecture 2

EITF25 Internet Techniques and Applications L5: Wide Area Networks (WAN) Stefan Höst

The difference between TCP/IP, UDP/IP and Multicast sockets. How servers and clients communicate over sockets

Architecture and Performance of the Internet

Creating a Simple, Multithreaded Chat System with Java

Network Layers. CSC358 - Introduction to Computer Networks

Chapter 3. Internet Applications and Network Programming

Computer Networks UDP and TCP

Introduction to Computer Networks

Transport Layer Protocols

Network Programming with Sockets. Process Management in UNIX

Lecture 28: Internet Protocols

Internet Packets. Forwarding Datagrams

Socket Programming in C/C++

Computer Networks/DV2 Lab

Lecture 2-ter. 2. A communication example Managing a HTTP v1.0 connection. G.Bianchi, G.Neglia, V.Mancuso

Java Network Programming. The java.net package contains the Socket class. This class speaks TCP (connection-oriented protocol).

Assignment 4 Solutions

Abhijit A. Sawant, Dr. B. B. Meshram Department of Computer Technology, Veermata Jijabai Technological Institute

TCP/IP Fundamentals. OSI Seven Layer Model & Seminar Outline

Computer Networks & Security 2014/2015

Course Overview: Learn the essential skills needed to set up, configure, support, and troubleshoot your TCP/IP-based network.

Network/Socket Programming in Java. Rajkumar Buyya

NETWORKING FEATURES OF THE JAVA PROGRAMMING LANGUAGE

8.2 The Internet Protocol

q Connection establishment (if connection-oriented) q Data transfer q Connection release (if conn-oriented) q Addressing the transport user

Socket programming. Complement for the programming assignment INFO-0010

Application. Transport. Network. Data Link. Physical. Network Layers. Goal

Tutorial on Socket Programming

Computer Networks. Chapter 5 Transport Protocols

IP - The Internet Protocol

Objectives of Lecture. Network Architecture. Protocols. Contents

CS335 Sample Questions for Exam #2

IP address format: Dotted decimal notation:

Computer Networks Practicum 2015

First Workshop on Open Source and Internet Technology for Scientific Environment: with case studies from Environmental Monitoring

What is CSG150 about? Fundamentals of Computer Networking. Course Outline. Lecture 1 Outline. Guevara Noubir noubir@ccs.neu.

Improved Digital Media Delivery with Telestream HyperLaunch

Ethernet. Ethernet. Network Devices

Introduction to Socket Programming Part I : TCP Clients, Servers; Host information

Network-based Applications. Pavani Diwanji David Brown JavaSoft

NAT & IP Masquerade. Internet NETWORK ADDRESS TRANSLATION INTRODUCTION. NAT & IP Masquerade Page 1 of 5. Internal PC

Distributed Systems. 2. Application Layer

Network layer: Overview. Network layer functions IP Routing and forwarding

Access Control: Firewalls (1)

Socket Programming. Request. Reply. Figure 1. Client-Server paradigm

ICOM : Computer Networks Chapter 6: The Transport Layer. By Dr Yi Qian Department of Electronic and Computer Engineering Fall 2006 UPRM

Remote login (Telnet):

CSIS CSIS 3230 Spring Networking, its all about the apps! Apps on the Edge. Application Architectures. Pure P2P Architecture

The POSIX Socket API

Note! The problem set consists of two parts: Part I: The problem specifications pages Part II: The answer pages

TP1 : Correction. Rappels : Stream, Thread et Socket TCP

Overview. Securing TCP/IP. Introduction to TCP/IP (cont d) Introduction to TCP/IP

Chapter 1: Introduction

Transcription:

Data Communication & Networks G22.2262-001 Session 10 - Main Theme Java Sockets Dr. Jean-Claude Franchitti New York University Computer Science Department Courant Institute of Mathematical Sciences 1

Agenda Internet Transport-Layer Protocols Multiplexing / Demultiplexing Socket Programming 2

Part I Internet Transport-Layer Protocols 3

Internet Transport-Layer Protocols Reliable, in-order delivery TCP congestion control flow control application transport network data link physical network data link physical network data link physical connection setup Unreliable, unordered delivery: UDP no-frills extension of best-effort IP Services not available: delay guarantees network data link physical network data link physical network data link physical application transport network data link physical bandwidth guarantees 4

Part II Multiplexing / Demultiplexing 5

Multiplexing/Demultiplexing Demultiplexing at rcv host: delivering received segments to correct socket = socket = process Multiplexing at send host: gathering data from multiple sockets, enveloping data with header (later used for demultiplexing) application P3 P1 P1 application P2 P4 application transport transport transport network network network link link link physical physical host 1 host 2 host 3 physical 6

How Demultiplexing Works Host receives IP datagrams each datagram has source IP address, destination IP address each datagram carries 1 transport-layer segment each segment has source, destination port number (recall: well-known port numbers for specific applications) Host uses IP addresses & port numbers to direct segment to appropriate socket 32 bits source port # dest port # other header fields application data (message) TCP/UDP segment format 7

Connectionless Demultiplexing Create sockets with port numbers: DatagramSocket mysocket1 = new DatagramSocket(99111) ; DatagramSocket mysocket2 = new DatagramSocket(99222) ; UDP socket identified by two-tuple: (dest IP address, dest port number) When host receives UDP segment: checks destination port number in segment directs UDP segment to socket with that port number IP datagrams with different source IP addresses and/or source port numbers directed to same socket 8

Connectionless Demux (cont.) DatagramSocket serversocket = new DatagramSocket(6428); P2 P3 P1 P1 SP: 6428 DP: 9157 SP: 6428 DP: 5775 SP: 9157 SP: 5775 client IP: A DP: 6428 server IP: C DP: 6428 Client IP:B SP provides return address 9

Connection-Oriented Demux TCP socket identified by 4-tuple: source IP address source port number dest IP address dest port number recv host uses all four values to direct segment to appropriate socket Server host may support many simultaneous TCP sockets: each socket identified by its own 4-tuple Web servers have different sockets for each connecting client non-persistent HTTP will have different socket for each request 10

Connection-Oriented Demux (cont.) P1 P4 P5 P6 P2 P1 P3 SP: 5775 DP: 80 S-IP: B D-IP:C SP: 9157 SP: 9157 client IP: A DP: 80 S-IP: A D-IP:C server IP: C DP: 80 S-IP: B D-IP:C Client IP:B 11

Part III Socket Programming 12

Socket Programming Goal: learn how to build client/server application that communicate using sockets Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm two types of transport service via socket API: unreliable datagram reliable, byte streamoriented socket a host-local, application-created, OS-controlled interface (a door ) into which application process can both send and receive messages to/from another application process 13

Socket Programming Using TCP Socket: a door between application process and end-endtransport protocol (UCP or TCP) TCP service: reliable transfer of bytes from one process to another controlled by application developer controlled by operating system process socket TCP with buffers, variables internet process socket TCP with buffers, variables controlled by application developer controlled by operating system host or server host or server 14

Socket Programming With TCP Client must contact server server process must first be running server must have created socket (door) that welcomes client s contact Client contacts server by: creating client-local TCP socket specifying IP address, port number of server process When client creates socket: client TCP establishes connection to server TCP When contacted by client, server TCP creates new socket for server process to communicate with client allows server to talk with multiple clients source port numbers used to distinguish clients (more in Chap 3) application viewpoint TCP provides reliable, in-order transfer of bytes ( pipe ) between client and server 15

Stream Jargon A stream is a sequence of characters that flow into or out of a process An input stream is attached to some input source for the process (e.g., keyboard or socket) An output stream is attached to an output source (e.g., monitor or socket) 16

outtoserver infromserver infromuser Socket Programming With TCP Example client-server app: 1) client reads line from standard input (infromuser stream), sends to server via socket (outtoserver stream) 2) server reads line from socket 3) server converts line to uppercase, sends back to client 4) client reads, prints modified line from socket (infromserver stream) Client Process process keyboard input stream output stream to network monitor client TCP clientsocket socket input stream from network TCP socket 17

Client/Server Socket Interaction: TCP Server (running on hostid) Client create socket, port=x, for incoming request: welcomesocket = ServerSocket() wait for incoming connection request connectionsocket = welcomesocket.accept() read request from connectionsocket TCP connection setup create socket, connect to hostid, port=x clientsocket = Socket() send request using clientsocket write reply to connectionsocket close connectionsocket read reply from clientsocket close clientsocket 18

Example: Java Client (TCP) import java.io.*; import java.net.*; class TCPClient { Create input stream Create client socket, connect to server Create output stream attached to socket 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()); 19

Example: Java Client (TCP), cont. Create input stream attached to socket Send line to server Read line from server 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(); } } 20

Example: Java Server (TCP) import java.io.*; import java.net.*; class TCPServer { Create welcoming socket at port 6789 Wait, on welcoming socket for contact by client Create input stream, attached to socket 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())); 21

Example: Java Server (TCP), cont. Create output stream, attached to socket Read in line from socket DataOutputStream outtoclient = new DataOutputStream(connectionSocket.getOutputStream()); clientsentence = infromclient.readline(); capitalizedsentence = clientsentence.touppercase() + '\n'; Write out line to socket } } } outtoclient.writebytes(capitalizedsentence); End of while loop, loop back and wait for another client connection 22

Socket Programming With UDP UDP: no connection between client and server no handshaking sender explicitly attaches IP address and port of destination to each packet server must extract IP address, port of sender from received packet UDP: transmitted data may be received out of order, or lost application viewpoint UDP provides unreliable transfer of groups of bytes ( datagrams ) between client and server 23

Client/Server Socket Interaction: UDP Server (running on hostid) Client create socket, port=x, for incoming request: serversocket = DatagramSocket() read request from serversocket create socket, clientsocket = DatagramSocket() Create, address (hostid, port=x, send datagram request using clientsocket write reply to serversocket specifying client host address, port number read reply from clientsocket close clientsocket 24

sendpacket receivepacket infromuser Example: Java Client (UDP) keyboard monitor Client Process process Output: sends packet (TCP sent byte stream ) input stream UDP packet UDP packet Input: receives packet (TCP received byte stream ) client clientsocket UDP socket UDP socket to network from network 25

Example: Java Client (UDP) import java.io.*; import java.net.*; Create input stream Create client socket Translate hostname to IP address using DNS 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(); 26

Example: Java Client (UDP), cont. Create datagram with data-to-send, length, IP addr, port Send datagram to server Read datagram from server } 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(); } 27

Example: Java Server (UDP) import java.io.*; import java.net.*; Create datagram socket at port 9876 Create space for received datagram Receive datagram class UDPServer { public static void main(string args[]) throws Exception { DatagramSocket serversocket = new DatagramSocket(9876); byte[] receivedata = new byte[1024]; byte[] senddata = new byte[1024]; while(true) { DatagramPacket receivepacket = new DatagramPacket(receiveData, receivedata.length); serversocket.receive(receivepacket); 28

Example: Java Server (UDP), cont. Get IP addr port #, of sender String sentence = new String(receivePacket.getData()); InetAddress IPAddress = receivepacket.getaddress(); int port = receivepacket.getport(); Create datagram to send to client Write out datagram to socket } } String capitalizedsentence = sentence.touppercase(); senddata = capitalizedsentence.getbytes(); DatagramPacket sendpacket = new DatagramPacket(sendData, senddata.length, IPAddress, port); serversocket.send(sendpacket); } End of while loop, loop back and wait for another datagram 29

Part IV Conclusion 30

Assignment & Readings Final Project (due 05/19/15) Assigned after the last class Readings Java.Net Package Documentation on Sun s Java Web site http://java.sun.com/docs/books/tutorial/networking/sockets/ 31

Next Session: IP Multicast 32