1 Java Networking – Part I CS 236607, Spring 2008/9.

Slides:



Advertisements
Similar presentations
1 Ports and IPv6. 2 Ports Transmission Control Protocol (TCP) or the User Datagram Protocol (UDP), used for communication Generally speaking, a computer.
Advertisements

Network Programming Chapter 11 Lecture 6. Networks.
Basic Socket Programming with Java. What is a socket?  Generally refers to a stream connecting processes running in different address spaces (across.
Socket Programming.
A CHAT CLIENT-SERVER MODULE IN JAVA BY MAHTAB M HUSSAIN MAYANK MOHAN ISE 582 FALL 2003 PROJECT.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
1 Networking with Java 2: The Server Side. 2 Some Terms Mentioned Last Week TCP -Relatively slow but enables reliable byte-stream transmission UDP -Fast.
Java Socket Support Presentation by: Lijun Yuan Course Number: cs616.
1 © 2003, Cisco Systems, Inc. All rights reserved. CCNA 1 v3.0 Module 11 TCP/IP Transport and Application Layers.
McGraw-Hill©The McGraw-Hill Companies, Inc., 2004 Application Layer PART VI.
Networks 1 CS502 Spring 2006 Network Input & Output CS-502 Operating Systems Spring 2006.
Networking with Java 1: The Client Side. Introduction to Networking.
1 Java Networking – part I CS , Winter 2007/8.
Networking Support In Java 2 Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
CEG3185 Tutorial 4 Prepared by Zhenxia Zhang Revised by Jiying Zhao (2015w)
Process-to-Process Delivery:
1 Networking with Java. 2 Introduction to Networking.
Socket Programming -What is it ? -Why bother ?. Basic Interface for programming networks at transport level It is communication end point Used for inter.
SOCKET PROGRAMMING. Client/Server Communication At a basic level, network-based systems consist of a server, client, and a media for communication as.
Computer Networks  Network - A system of computers interconnected in order to share information.  Data transmission - consists of sending and receiving.
TCP/IP protocols Communication over Internet is mostly TCP/IP (Transmission Control Protocol over Internet Protocol) TCP/IP "stack" is software which allows.
Chapter 17 Networking Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William Stallings.
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.
TCP/IP: Basics1 User Datagram Protocol (UDP) Another protocol at transport layer is UDP. It is Connectionless protocol i.e. no need to establish & terminate.
 Socket  The combination of an IP address and a port number. (RFC 793 original TCP specification)  The name of the Berkeley-derived application programming.
© 2007 Cisco Systems, Inc. All rights reserved.Cisco Public 1 Version 4.0 Network Services Networking for Home and Small Businesses – Chapter 6.
Jozef Goetz, Application Layer PART VI Jozef Goetz, Position of application layer The application layer enables the user, whether human.
CS 424/524: Introduction to Java Programming Lecture 25 Spring 2002 Department of Computer Science University of Alabama Joel Jones.
DBI Representation and Management of Data on the Internet.
© 2007 Cisco Systems, Inc. All rights reserved.Cisco Public 1 Version 4.0 OSI Transport Layer Network Fundamentals – Chapter 4.
TCP/IP Transport and Application (Topic 6)
 TCP (Transport Control Protocol) is a connection-oriented protocol that provides a reliable flow of data between two computers.  TCP/IP Stack Application.
Sockets process sends/receives messages to/from its socket
RGEC MEERUT(IWT CS703) 1 Java Networking RGEC Meerut.
Dr. John P. Abraham Professor University of Texas Pan American Internet Applications and Network Programming.
1. I NTRODUCTION TO N ETWORKS Network programming is surprisingly easy in Java ◦ Most of the classes relevant to network programming are in the java.net.
1 Networking Chapter Distributed Capabilities Communications architectures –Software that supports a group of networked computers Network operating.
CCNA 1 v3.0 Module 11 TCP/IP Transport and Application Layers.
1 Network Programming and Java Sockets. 2 Network Request Result a client, a server, and network Client Server Client machine Server machine Elements.
L 2 - 1 3( 1/ 20) : Java Network Programming. The Socket API The previous contents describe client-server interaction that application programs use when.
Introduction to Sockets “A socket is one endpoint of a two-way communication link between two programs running on the network. A socket is bound to a port.
ECEN “Internet Protocols and Modeling”, Spring 2012 Course Materials: Papers, Reference Texts: Bertsekas/Gallager, Stuber, Stallings, etc Class.
Socket Programming Introduction. Socket Definition A network socket is one endpoint in a two-way communication flow between two programs running over.
The Client-Server Model And the Socket API. Client-Server (1) The datagram service does not require cooperation between the peer applications but such.
CSI 3125, Preliminaries, page 1 Networking. CSI 3125, Preliminaries, page 2 Networking A network represents interconnection of computers that is capable.
Transmission Control Protocol (TCP) Internet Protocol (IP)
Prepared by Dr. Jiying Zhao University of Ottawa Canada.
UNIT-6. Basics of Networking TCP/IP Sockets Simple Client Server program Multiple clients Sending file from Server to Client Parallel search server.
1 COMP 431 Internet Services & Protocols Client/Server Computing & Socket Programming Jasleen Kaur February 2, 2016.
Computer Network Architecture Lecture 6: OSI Model Layers Examples 1 20/12/2012.
Agenda Socket Programming The OSI reference Model The OSI protocol stack Sockets Ports Java classes for sockets Input stream and.
SOCKET PROGRAMMING WITH JAVA By Collin Donaldson.
1 Network Communications A Brief Introduction. 2 Network Communications.
1 K. Salah Application Layer Module K. Salah Network layer duties.
Networking Mehdi Einali Advanced Programming in Java 1.
Network Programming. These days almost all devices.
UDP: User Datagram Protocol. What Can IP Do? Deliver datagrams to hosts – The IP address in a datagram header identify a host – treats a computer as an.
IST 201 Chapter 11 Lecture 2. Ports Used by TCP & UDP Keep track of different types of transmissions crossing the network simultaneously. Combination.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 33 Networking.
Prepared by: Dr. Abdallah Mohamed, AOU-KW Unit9: Internet programming 1.
Object-Orientated Analysis, Design and Programming
MCA – 405 Elective –I (A) Java Programming & Technology
Networking with Java 2.
Working at a Small-to-Medium Business or ISP – Chapter 7
Working at a Small-to-Medium Business or ISP – Chapter 7
Process-to-Process Delivery:
Internet Applications & Programming
Process-to-Process Delivery: UDP, TCP
Exceptions and networking
Presentation transcript:

1 Java Networking – Part I CS , Spring 2008/9

2 Menu Networking Basics  TCP, UDP, Ports, DNS, Client-Server Model TCP/IP in Java Sockets Next Tutorial: (Part II)URL  The java classes: URL, URLEncoder, URLConnection, HTTPURLConnection Datagrams Networking in JDBC

3 Networking Basics Computers running on the Internet communicate with each other using either the Transmission Control Protocol (TCP) or the User Datagram Protocol (UDP)

4 TCP (Transmission Control Protocol) A connection-based protocol that provides a reliable flow of data between two computers. Provides a point-to-point channel for applications that require reliable communications.  The Hypertext Transfer Protocol (HTTP), File Transfer Protocol (FTP), and Telnet are all examples of applications that require a reliable communication channel Guarantees that data sent from one end of the connection actually gets to the other end and in the same order it was sent. Otherwise, an error is reported.

5 UDP (User Datagram Protocol) A protocol that sends independent packets of data, called datagrams, from one computer to another with no guarantees about arrival. UDP is not connection-based like TCP and is not reliable:  Sender does not wait for acknowledgements  Arrival order is not guaranteed  Arrival is not guaranteed Used when speed is essential, even in cost of reliability  e.g. streaming media, games, Internet telephony, etc.

6 Ports Data transmitted over the Internet is accompanied by addressing information that identifies the computer and the port for which it is destined.  The computer is identified by its 32-bit IP address, which IP uses to deliver data to the right computer on the network. Ports are identified by a 16-bit number, which TCP and UDP use to deliver the data to the right application. Why don’t we specify the port in a Web browser?

7 Ports – Cont. Port numbers range from 0 to 65,535 (16-bit)  Ports are called well-known ports. They are reserved for use by well-known services: 20, 21: FTP 23: TELNET 25: SMTP 110: POP3 80: HTTP

8 Networking Classes in the JDK Through the classes in java.net, Java programs can use TCP or UDP to communicate over the Internet.  The URL, URLConnection, Socket, and ServerSocket classes all use TCP to communicate over the network.  The DatagramPacket, DatagramSocket, and MulticastSocket classes are for use with UDP.

9 TCP/IP in Java Accessing TCP/IP from Java is straightforward. The main functionality is in the following classes:  Java.net.InetAddress : Represents an IP address (either IPv4 or IPv6) and has methods for performing DNS lookup (next slide).  Java.net.Socket : Represents a TCP socket.  Java.net.ServerSocket : Represents a server socket which is capable of waiting for requests from clients.

10 DNS - Domain name system The Domain Name System (DNS) associates various sorts of information with so-called domain names. Most importantly, it serves as the "phone book" for the Internet by translating human-readable computer hostnames, e.g. into the IP addresses, e.g , that networking equipment needs to deliver information. It also stores other information such as the list of mail exchange servers that accept for a given domain.

11 DNS Lookup Example The following program performs a DNS lookup to find the IP numbers that are associated with a given domain name.

12 Client-Server Model A common paradigm for distributed applications Asymmetry in connection establishment:  Server waits for client requests at a well known address (IP+port)  Connection is established upon client request For example: Web servers and browsers

13 Sockets: Low-Level Networking A socket is one endpoint of a two-way communication link between two programs running on the network. An endpoint is a combination of an IP address and a port number. A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent.

14 Java Sockets Java wraps OS sockets (over TCP) by the objects of class java.net.Socket new Socket(String remoteHost, int remotePort) Creates a TCP socket and connects it to the remote host on the remote port (hand shake) Write and read using streams:  InputStream getInputStream()  OutputStream getOutputStream() The Socket API

15 SimpleClient Example This client tries to connect to a server (coming soon…) at the given port (command line arguments), then sends some output to the server, and finally receives some input which is printed on the screen. Can you think of a better place for the close action?

16 Class ServerSocket This class implements server sockets. A server socket waits for requests to come in over the network. It performs some operation based on that request, and then possibly returns a result to the requester. A server socket is technically not a socket: when a client connects to a server socket, a TCP connection is made, and a (normal) socket is created for each end point.

17 SimpleServer Example The server creates a server socket that listen on the port given at the command line. It then enters infinite loop doing the following: when a connection with a client is established it reads some input from the client (terminated with a 0 byte), sends back the message ‘Simon says:’ plus the input received, and closes the connection. Finally would be the right place…

18 Accepting Connections Usually, the accept() method is executed within an infinite loop  i.e., while(true){...} The accept method returns a new socket (with a new port) for the new channel. It blocks until connection is made Using threads to handle that interaction (not in our example), the server can handle several requests concurrently

19 Timeout You can set timeout values to the blocking accept() method of ServerSocket Use the method: serverSocket.setSoTimeout(milliseconds) If timeout is reached before the method returns, java.net.SocketTimeoutException is thrown.