1 CSCD 330 Network Programming Fall 2013 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright 1996-2007 Lecture 8a Application.

Slides:



Advertisements
Similar presentations
Socket UDP H. Fauconnier 1-1 M2-Internet Java. UDP H. Fauconnier M2-Internet Java 2.
Advertisements

2: Application Layer1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r Sockets are explicitly created, used, released by applications.
Client-Server Paradigm and Performance L. Grewe. 2 Review: Basic Client-Server Request/Reply Paradigm Typical Internet app has two pieces: client and.
Network Programming and Java Sockets
Application Layer 2-1 Chapter 2 Application Layer Computer Networking: A Top Down Approach 6 th edition Jim Kurose, Keith Ross Application Layer – Lecture.
2: Application Layer 1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm.
9/23/2003-9/25/2003 Sockets & DNS September 23-25, 2003.
2: Application Layer1 Data Communication and Networks Lecture 12 Java Sockets November 30, 2006.
2: Application Layer1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm.
1 Overview r Socket programming with TCP r Socket programming with UDP r Building a Web server.
1 Review of Previous Lecture r Electronic Mail r DNS r P2P file sharing.
Internet and Intranet Protocols and Applications Lecture 4: Application Layer 3: Socket Programming February 8, 2005 Arthur Goldberg Computer Science Department.
2: Application Layer1 Chapter 2 (continued) Application Layer – part 2 Computer Networking: A Top Down Approach Featuring the Internet, 3 rd edition. Jim.
Lecture 11 Java Socket Programming CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Joonbok Lee.
Socket programming with UDP and TCP. Socket Programming with TCP Connection oriented – Handshaking procedure Reliable byte-stream.
2: Application Layer1 Socket Programming. 2: Application Layer2 Socket-programming using TCP Socket: a door between application process and end- end-transport.
2: Application Layer1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,
1 Network Layers Application Transport Network Data-Link Physical bits.
Protocols Rules for communicating between two entities (e.g., a client and a server) “A protocol definition specifies how distributed system elements interact.
2: Application Layer 1 Socket Programming Computer Networking: A Top Down Approach Featuring the Internet, 3 rd edition. Jim Kurose, Keith Ross Addison-Wesley,
JAVA Socket Programming Joonbok Lee KAIST.
2: Application Layer 1 Socket Programming TCP and UDP.
JAVA Socket Programming Source: by Joonbok Lee, KAIST, 2003.
ECE5650: Network Programming
1 1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm r two types of.
2: Application Layer1 Chapter 2 Application Layer Computer Networking: A Top Down Approach Featuring the Internet, 2 nd edition. Jim Kurose, Keith Ross.
2: Application Layer1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,
2: Application Layer1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm.
CS 3830 Day 11 Introduction : Application Layer 2 Server-client vs. P2P: example Client upload rate = u, F/u = 1 hour, u s = 10u, d min ≥ u s.
Chapter 2 Application Layer Computer Networking: A Top Down Approach, 5 th edition. Jim Kurose, Keith Ross Addison-Wesley, April A note on the use.
Winter 2002Suprakash Datta1 Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm.
-1- Georgia State UniversitySensorweb Research Laboratory CSC4220/6220 Computer Networks Dr. WenZhan Song Associate Professor, Computer Science.
Socket Programming Lee, Sooyong
Network Programming and Sockets CPSC 363 Computer Networks Ellen Walker Hiram College (Includes figures from Computer Networking by Kurose & Ross, © Addison.
Socket Programming Tutorial. Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm.
Java Socket programming. Socket programming with TCP.
NETWORK PROGRAMMING.
Socket-Programming.  Establish contact (connection).  Exchange information (bi-directional).  Terminate contact.
2: Application Layer1 Socket programming Socket API Explicitly created, used, released by apps Client/server paradigm Two types of transport service via.
1 CSCD 330 Network Programming Spring 2014 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 7 Application.
Network Applications: DNS, UDP Socket 1/24/ Outline  Recap r DNS r Network application programming: UDP.
Lab assignments in Computer Networks at Faculty of Electronic Engineering - Nis.
Chapter 2 Application Layer Application 2-1. Chapter 2: Application layer 2.1 Principles of network applications 2.2 Web and HTTP 2.3 FTP 2.4 Electronic.
1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm r two types of.
CSI 3125, Preliminaries, page 1 Networking. CSI 3125, Preliminaries, page 2 Inetaddress Class When establishing a connection across the Internet, addresses.
Network Applications: DNS Details; UDP Network App Programming
Data Communications and Computer Networks Chapter 2 CS 3830 Lecture 11 Omar Meqdadi Department of Computer Science and Software Engineering University.
1 All rights reserved to Chun-Chuan Yang Upon completion you will be able to: The OSI Model and the TCP/IP Protocol Suite Understand the architecture of.
2: Application Layer1 Network applications: some jargon Process: program running within a host. r within same host, two processes communicate using interprocess.
Topic: Network programming
Socket Programming Socket Programming Overview
Transport layer (last part) Application layer
DNS: Domain Name System
Socket programming with TCP
Chapter 2: outline 2.1 principles of network applications
Socket programming - Java
CSCD 330 Network Programming
Socket Programming Socket Programming Overview
Socket Programming.
CSCD 330 Network Programming
Java Socket Programming
Socket Programming 2: Application Layer.
DNS: Domain Name System
CSCD 330 Network Programming
CPSC 441 UDP Socket Programming
Chapter 2: Application layer
DNS: Domain Name System
DNS: Domain Name System
Socket Programming with UDP
Presentation transcript:

1 CSCD 330 Network Programming Fall 2013 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 8a Application Layer – Socket Programming in Java - UDP Reading: Chapter 2 and Relevant Links

UDP Sockets in Java Less complex Used in bandwidth-limited applications, where the overhead associated with resending packets is not tolerable A good example: real-time applications Incurs fewer overheads

UDP

4 UDP Socket Programming UDP no real “connection” between client and server No handshaking Sender attaches IP address and destination port to each packet Server must extract IP address and port of sender from received packet, so answer can be sent back! UDP, transmitted data may be received out of order, or lost

5 Client/server socket interaction: UDP close clientSocket Server (running on hostid ) ‏ read reply from clientSocket create socket, clientSocket = DatagramSocket()‏ Client Create, address ( hostid, port=50)‏ send datagram request using clientSocket create socket, port= 50, for incoming request: serverSocket = DatagramSocket()‏ read request from serverSocket write reply to serverSocket specifying client host address, port number

6 UDP Summary No connection setup – no “pipe” Main Differences between UDP vs TCP Each batch of bytes sent with attached address information No special ServerSocket class in java

UDP Summary Create a packet Push it out into the network through a socket Server accepts the packet addressed to him Mail is a lot like UDP Each letter needs the address of the destination Independent letters sent to the same address

The Two Major Classes DatagramSocket Class In order for two agents to talk to each other over a UDP connection, a DatagramSocket object is created to ensure they both connected to a port on their local machines. DatagramPacket Class Each DatagramPacket contains a data buffer, the address of the remote host to send the data to, and the port number the remote agent is listening to

9 The DatagramPacket class stuffs bytes of data into UDP packets called datagrams and lets you unstuff datagrams that you receive A DatagramSocket sends and receives data using UDP packets, represented as DatagramPacket objects The remote process can receive the data in the form of a DatagramPacket by calling the receive() method on its DatagramSocket How does it work?

10 Java Classes for UDP Datagrams for connectionless protocol Two classes implement datagrams in Java: java.net.DatagramPacket java.net.DatagramSocket DatagramPacket is actual packet of information, an array of bytes, that is transmitted over the network. DatagramSocket is socket that sends and receives DatagramPackets across the network. Think of DatagramPacket as a letter and DatagramSocket as the mailbox that the mail carrier uses to pick up and drop off your letters Need both classes for UDP sockets

11 Java Classes for UDP DatagramPacket class provides programmer with two constructors. First is for DatagramPackets that receive data Constructor needs Array to store the data Amount of data to receive Second is for DatagramPackets that send data Constructor needs Array to store the data Amount of data to send Plus destination address and port number

12 Java Classes for UDP DatgramSocket represents connectionless socket It provides two constructors, 1. Programmer can specify a port OR 2. Allow system to randomly use a port Methods Two most important methods, send() and receive()‏ Each takes an argument of a constructed DatagramPacket send() method Data in packet is sent to specified host and port receive() method Will block execution until a packet is received by underlying socket, then data copied into packet provided

Running Example Capitalize Echo Client/Server  Client  User types line of text  Client program sends line to server  Server  Server receives line of text  Capitalizes all the letters  Sends modified line to client  Client  Receives line of text  Displays M2-Internet Java 13 H. Fauconnier

14 Sentence Capitalizer (Again)‏ 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(); Create input stream Create client socket Translate hostname to IP address using DNS

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

16 Sentence Capitalizer (Again)‏ Example: Java server (UDP)‏ import java.io.*; import java.net.*; 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); Create datagram socket at port 9876 Create space for received datagram Receive datagram

17 Example: Java server (UDP), cont String sentence = new String(receivePacket.getData()); InetAddress IPAddress = receivePacket.getAddress(); int port = receivePacket.getPort(); String capitalizedSentence = sentence.toUpperCase(); sendData = capitalizedSentence.getBytes(); DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, port); serverSocket.send(sendPacket); } Get IP addr port #, of sender Write out datagram to socket End of while loop, loop back and wait for another datagram Create datagram to send to client

18 Summary Brief coverage of Java sockets - TCP/UDP Should be enough to get started Examples will be available as links on the main class page Will cover threads next First assignment will be a multi-threaded Web Server … Also, will practice client-server in the lab Do read references in RelatedLinks for more information

19 End References – king/datagrams/index.html There is a new assignment …. Ping Program