© Amir Kirsh Java Networking Written by Amir Kirsh.

Slides:



Advertisements
Similar presentations
Socket Programming ENTERPRISE JAVA. 2 Content  Sockets  Streams  Threads  Readings.
Advertisements

Multiplexing/Demux. CPSC Transport Layer 3-2 Multiplexing/demultiplexing application transport network link physical P1 application transport network.
Socket Programming By Ratnakar Kamath. What Is a Socket? Server has a socket bound to a specific port number. Client makes a connection request. Server.
© Amir Kirsh Java Networking Written by Amir Kirsh, Edited by Liron Blecher.
Using Processing Stream. Predefined Streams System.in InputStream used to read bytes from the keyboard System.out PrintStream used to write bytes to the.
1 Creating a network app Write programs that  run on different end systems and  communicate over a network.  e.g., Web: Web server software communicates.
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.
Network Programming CS3250. References Core Java, Vol. II, Chapter 3. Book examples are available from
Java Networking -- Socket Server socket class: ServerSocket wait for requests from clients. after a request is received, a client socket is generated.
CIS – Spring Instructors: Geoffrey Fox, Bryan Carpenter Computational Science and.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L22 (Chapter 25) Networking.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 25 Networking.
Socket Communication Sockets provide an abstraction of two-point communication The two sides only read/write without concern for how data is translated.
1 Fall 2005 Socket Programming Qutaibah Malluhi Computer Science and Engineering Qatar University.
© Amir Kirsh Threads Written by Amir Kirsh. 2 Lesson’s Objectives By the end of this lesson you will: Be familiar with the Java threads syntax and API.
Network/Socket Programming in Java Rajkumar Buyya.
CEG3185 Tutorial 4 Prepared by Zhenxia Zhang Revised by Jiying Zhao (2015w)
Greg Jernegan Brandon Simmons. The Beginning…  The problem Huge demand for internet enabled applications and programs that communicate over a network.
An program As a simple example of socket programming we can implement a program that sends to a remote site As a simple example of socket.
Socket programming 1. getByName import java.net.*; public class GetHostName { public static void main (String args[]) { String host = "
SOCKET PROGRAMMING. Client/Server Communication At a basic level, network-based systems consist of a server, client, and a media for communication as.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 12 Communicating over.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
An program As a simple example of socket programming we can implement a program that sends to a remote site As a simple example of socket.
DBI Representation and Management of Data on the Internet.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Echo Networking COMP
UDP vs TCP UDP Low-level, connectionless No reliability guarantee TCP Connection-oriented Not as efficient as UDP.
RGEC MEERUT(IWT CS703) 1 Java Networking RGEC Meerut.
Object Oriented Programming in Java Lecture 16. Networking in Java Concepts Technicalities in java.
Lecture 9 Network programming. Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on the Internet.
MSc Course in Advanced Distributed Systems Session 2.2: Practical CORBA Programming
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.
1 Network Programming and Java Sockets. 2 Network Request Result a client, a server, and network Client Server Client machine Server machine Elements.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae, VUW Networking COMP # 22.
Networks Sockets and Streams. TCP/IP in action server ports …65535 lower port numbers ( ) are reserved port echo7 time13 ftp20 telnet23.
 2003 Joel C. Adams. All Rights Reserved. Calvin CollegeDept of Computer Science(1/11) Java Sockets and Simple Networking Joel Adams and Jeremy Frens.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Networking and Concurrency COMP.
File IO Basics By Dan Fleck Coming up: Data Streams.
1 cs205: engineering software university of virginia fall 2006 Network Programming* * Just enough to make you dangerous Bill Cheswick’s map of the Internet.
CS390- Unix Programming Environment CS 390 Unix Programming Environment Java Socket Programming.
Networking Terminology: ISP (Internet service provider) – dialup, dsl, cable LAN (local area network) IP (internet protocol) address, eg
© Amir Kirsh Files and Streams in Java Written by Amir Kirsh.
Part 4: Network Applications Client-server interaction, example applications.
By Vivek Dimri. Basic Concepts on Networking IP Address – Protocol – Ports – The Client/Server Paradigm – Sockets The Java Networking Package – The InetAddress.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
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.
Java Programming II Java Network (I) Java Programming II.
1 Lecture 9: Network programming. 2 Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on.
Network Programming with Java java.net.InetAddress: public static void main(String[] args) throws UnknownHostException { InetAddress localAddress = InetAddress.getLocalHost();
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 Java API for distributed computing.
Generic Connection Framework Connection FileConnectionSocketConnectionHTTPConnection InputConnection OutputConnection StreamConnection.
SOCKET PROGRAMMING WITH JAVA By Collin Donaldson.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Echo Networking COMP
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:
Java 13. Networking public class SumTest {
Echo Networking COMP
Lecture 21 Sockets 1 (Not in D&D) Date.
RADE new features via JAVA
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.
Networking with Java 2.
PRESENTED To: Sir Abid………. PRESENTED BY: Insharah khan………. SUBJECT:
COP 4610L: Applications in the Enterprise Spring 2005
Multiplexing/Demux.
Review Communication via paired sockets, one local and one remote
Presentation transcript:

© Amir Kirsh Java Networking Written by Amir Kirsh

2 Lesson’s Objectives By the end of this lesson you will: Be able to implement a client-server network application in Java Be familiar with the sockets API of Java

Agenda Downloading a web page TCP Client TCP Server What’s beyond Exercise

4 Downloading a web page public static void main (String args[]) { String line; try { URL u = new URL(args[0]); DataInputStream htmlPage = new DataInputStream(u.openStream()); while ((line = htmlPage.readLine()) != null) { System.out.println(line); } } catch (Exception e) { System.err.println(e); // naive treatment } }

5 Dealing with URL encoding public static void main (String args[]) { String line; try { URL u = new URL( URLEncoder.encode( args[0], Charset.forName("UTF-8") ) ); DataInputStream htmlPage = new DataInputStream(u.openStream()); while ((line = htmlPage.readLine()) != null) { System.out.println(line); } } catch (Exception e) { System.err.println(e); // naive treatment } }

Agenda Downloading a web page TCP Client TCP Server What’s beyond Exercise

7 Simple TCP Echo Client public static void main(String[] args) { Socket socket; DataInputStream inputStream; DataInputStream userInput; PrintStream outputStream; String line = ""; try { socket = new Socket("localhost", 7000); inputStream = new DataInputStream( socket.getInputStream()); // not really used here outputStream = new PrintStream( socket.getOutputStream()); userInput = new DataInputStream(System.in); while(!line.equals("!")) { line = userInput.readLine(); outputStream.println(line); System.out.println(theInputStream.readLine()); } } …

8 Simple TCP Echo Client – cont’ public static void main(String[] args) { try { … } catch (Exception e) { System.err.println(e); } finally { try { socket.close(); } catch (IOException e) { // log and ignore } } }

Agenda Downloading a web page TCP Client TCP Server What’s beyond Exercise

10 Simple TCP Echo Server public static void main(String[] args) { Socket socket; ServerSocket server = new ServerSocket(7000); DataInputStream inputStream; PrintStream outputStream; String line = ""; try { socket = server.accept(); // blocking inputStream = new DataInputStream( socket.getInputStream()); outputStream = new PrintStream( socket.getOutputStream()); while(!line.equals("!")) { line = inputStream.readLine(); outputStream.println(line); System.out.println(line); } } …

11 Simple TCP Echo Server – cont’ public static void main(String[] args) { try { … } catch (Exception e) { System.err.println(e); } finally { try { socket.close(); } catch (IOException e) { // log and ignore } } }

Agenda Downloading a web page TCP Client TCP Server What’s beyond Exercise

13 What’s beyond -UDP java.net.DatagramSocket -Multicast java.net.MulticastSocket -Selector and Channels (and nio in general) java.nio.channels -Servlets (and JSP) -Web Services -RMI; EJB

Agenda Downloading a web page TCP Client TCP Server What’s beyond Exercise

15 Exercise Write a simple chat server and chat client. The chat client will get input from the keyboard and send it, at EOL, to the chat server. Messages from the server will be printed to the client’s Console. The chat server will distribute all messages to all the clients, with the id of the sending client. Use threads appropriately in the server!

16 That concludes this chapter amirk at mta ac il