1 Netprog 2002 TCP/IP UDP/IP in Java Based on Java Network Programming and Distributed Computing.

Slides:



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

Java Network Programming Vishnuvardhan.M. Dept. of Computer Science - SSBN Java Overview Object-oriented Developed with the network in mind Built-in exception.
Umut Girit  One of the core members of the Internet Protocol Suite, the set of network protocols used for the Internet. With UDP, computer.
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.
Socket Programming.
User Datagram Protocol. Introduction UDP is a connectionless transport protocol, i.e. it doesn't guarantee either packet delivery or that packets arrive.
Prepared By E. Musa Alyaman1 User Datagram Protocol (UDP) Chapter 5.
1 Java Networking – Part I CS , Spring 2008/9.
2: Application Layer1 Data Communication and Networks Lecture 12 Java Sockets November 30, 2006.
1 Overview r Socket programming with TCP r Socket programming with UDP r Building a Web server.
Java Socket Support Presentation by: Lijun Yuan Course Number: cs616.
1 School of Computing Science Simon Fraser University CMPT 771/471: Internet Architecture and Protocols Socket Programming Instructor: Dr. Mohamed Hefeeda.
2: Application Layer1 Socket Programming. 2: Application Layer2 Socket-programming using TCP Socket: a door between application process and end- end-transport.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 25 Networking.
1 Network Layers Application Transport Network Data-Link Physical bits.
Comunicação entre processos baseada em troca de mensagens através de sockets sobre IP Alcides Calsavara.
Julia Ljunbjörk and Anita Mugenyi. What is a socket? Like a house Between the layers.
2: Application Layer 1 Socket Programming TCP and UDP.
JAVA Socket Programming Source: by Joonbok Lee, KAIST, 2003.
Socket Programming -What is it ? -Why bother ?. Basic Interface for programming networks at transport level It is communication end point Used for inter.
Babak Esfandiari (based on slides by Qusay Mahmoud)
CS4273: Distributed System Technologies and Programming I Lecture 5: Java Socket Programming.
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.
 Socket  The combination of an IP address and a port number. (RFC 793 original TCP specification)  The name of the Berkeley-derived application programming.
Windows Programming Using C# Internet Programming.
VIII. UDP Datagrams and Sockets. The User Datagram Protocol (UDP) is an alternative protocol for sending data over IP that is very quick, but not reliable:
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.
Vassil Roussev 2 A socket is the basic remote communication abstraction provided by the OS to processes. controlled by operating system.
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.
 TCP (Transport Control Protocol) is a connection-oriented protocol that provides a reliable flow of data between two computers.  TCP/IP Stack Application.
RGEC MEERUT(IWT CS703) 1 Java Networking RGEC Meerut.
Socket Programming Tutorial. Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm.
Distributed Systems Concepts and Design Chapter 4.
1 Chapter 28 Networking. 2 Objectives F To comprehend socket-based communication in Java (§28.2). F To understand client/server computing (§28.2). F To.
Java Sockets Programming
Java Socket programming. Socket programming with TCP.
UDP User Datagram Protocol. User Datagram Protocol (UDP) UDP is the protocol available to network programmers who wish to send datagrams UDP datagrams.
L 2 - 1 3( 1/ 20) : Java Network Programming. The Socket API The previous contents describe client-server interaction that application programs use when.
2: Application Layer1 Socket programming Socket API Explicitly created, used, released by apps Client/server paradigm Two types of transport service via.
CSCE 515: Computer Network Programming UDP Socket Wenyuan Xu Department of Computer Science and Engineering.
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.
Programming with UDP – II Covered Subjects: Creating UDP sockets Client Server Sending data Receiving data Connected mode.
CSI 3125, Preliminaries, page 1 Networking. CSI 3125, Preliminaries, page 2 Networking A network represents interconnection of computers that is capable.
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.
Java Network Programming Network Programming Spring 2000 Jeffrey E. Care
CSI 3125, Preliminaries, page 1 Networking. CSI 3125, Preliminaries, page 2 Inetaddress Class When establishing a connection across the Internet, addresses.
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.
UDP User Datagram Protocol. About the UDP A commonly used transport protocol Does not guarantee either packet delivery or order The packets may travel.
Socket programming in C. Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm.
UDP Programming. Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 2/86 Overview.
Data Communications and Computer Networks Chapter 2 CS 3830 Lecture 11 Omar Meqdadi Department of Computer Science and Software Engineering University.
Client/Server Design Issues Based on Java Network Programming and Distributed Computing, Chapter 6 Also Online Java Tutorial, Sun.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 33 Networking.
Network Programming Communication between processes Many approaches:
Beyond HTTP Up to this point we have been dealing with software tools that run on browsers and communicate to a server that generates files that can be.
Socket programming with TCP
UDP Sockets Programming
Chapter 2: outline 2.1 principles of network applications
Socket programming - Java
CSCD 330 Network Programming
Socket Programming.
CSCD 330 Network Programming
Socket Programming 2: Application Layer.
CPSC 441 UDP Socket Programming
Chapter 2: Application layer
Socket Programming with UDP
Based on Java Network Programming and Distributed Computing
Presentation transcript:

1 Netprog 2002 TCP/IP UDP/IP in Java Based on Java Network Programming and Distributed Computing

2 Netprog 2002 TCP/IP UDP Advantages Less overhead (no connection establishment) More efficient (no guaranteed delivery) Real-time applications (no error checking or flow-control) E.g., weather, time, video, audio, games Data reception from more than one machine

3 Netprog 2002 TCP/IP Internet Addresses java.net.InetAddress class You get an address by using static methods: ad = InetAddress.getByName(hostname); myAddress = InetAddress.getLocalHost();

4 Netprog 2002 TCP/IP Printing Internet Addresses You get information from an InetAddress by using methods: ad.getHostName(); ad.getHostAddress(); Example.

5 Netprog 2002 TCP/IP UDP Sockets Programming Sending/Receiving data. java.net.DatagramPacket class Creating UDP sockets. Client Server java.net.DatagramSocket class

6 Netprog 2002 TCP/IP Creating a UDP packet // to receive data from a remote machine DatagramPacket packet = new DatagramPacket(new byte[256], 256); // to send data to a remote machine DatagramPacket packet = new DatagramPacket( new byte[128], 128, address, port );

7 Netprog 2002 TCP/IP Creating UDP sockets A UDP socket can be used both for reading and writing packets. Write operations are asynchronous; however, read operations are blocking. Since there is no guaranteed delivery, a single-threaded application could stall.

8 Netprog 2002 TCP/IP Creating UDP Sockets // A client datagram socket: DatagramSocket clientSocket = new DatagramSocket(); // A server datagram socket: DatagramSocket serverSocket = new DatagramSocket(port);

9 Netprog 2002 TCP/IP Listening for UDP Packets // create datagram packet... // create datagram server socket... boolean finished = false; while ( ! finished ) { serverSocket.receive (packet); // process the packet } serverSocket.close();

10 Netprog 2002 TCP/IP Processing UDP Packets ByteArrayInputStream bin = new ByteArrayInputStream( packet.getData() ); DataInputStream din = new DataInputStream(bin); // read the contents of the packet

11 Netprog 2002 TCP/IP Sending UDP Packets // create datagram packet... // create datagram client socket... boolean finished = false; while ( ! finished ) { // write data to packet buffer clientSocket.send (packet); // see if there is more to send }

12 Netprog 2002 TCP/IP Sending UDP packets When you receive a packet, the ip and port number of the sender are set in the DatagramPacket. You can use the same packet to reply, by overwriting the data, using the method: packet.setData(newbuffer);

13 Netprog 2002 TCP/IP Non-blocking I/O receiving UDP packets You can set a time-out in milliseconds to determine how long a read operation blocks, before throwing an exception. socket.setSoTimeout(duration); If the duration given in milliseconds is exceeded, an exception is thrown: java.io.InterruptedException

14 Netprog 2002 TCP/IP Typical UDP client code Create UDP socket to contact server (with a given hostname and service port number) Create UDP packet. Call send(packet), sending request to the server. Possibly call receive(packet) (if we need a reply).

15 Netprog 2002 TCP/IP Typical UDP Server code Create UDP socket listening to a well known port number. Create UDP packet buffer Call receive(packet) to get a request, noting the address of the client. Process request and send reply back with send(packet).

16 Netprog 2002 TCP/IP Debugging Debugging UDP can be difficult. Write routines to print out addresses. Use a debugger. Include code that can handle unexpected situations.

17 Netprog 2002 TCP/IP Asynchronous Errors What happens if a client sends data to a server that is not running? ICMP “port unreachable” error is generated by receiving host and send to sending host. The ICMP error may reach the sending host after send() has already returned! The next call dealing with the socket could return the error.