© Amir Kirsh Java Networking Written by Amir Kirsh, Edited by Liron Blecher.

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.
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.
Programming Applets How do Applets work ? This is an HTML page This is the applet’s code It has a link to an applet.
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 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.
Projekt współfinansowany przez Unię Europejską w ramach Europejskiego Funduszu Społecznego „Networking”
Socket Communication Sockets provide an abstraction of two-point communication The two sides only read/write without concern for how data is translated.
Java I/O – what does it include? Command line user interface –Initial arguments to main program –System.in and System.out GUI Hardware –Disk drives ->
Java Review 2. The Agenda The following topics were highlighted to me as issues: –File IO (Rem) –Wrappers (Rem) –Interfaces (Rem) –Asymptotic Notation.
1 Fall 2005 Socket Programming Qutaibah Malluhi Computer Science and Engineering Qatar University.
CSE 341, S. Tanimoto Java networking- 1 Java Networking Motivation Network Layers Using Sockets A Tiny Server Applets URLs Downloading Images, MediaTracker.
CEG3185 Tutorial 4 Prepared by Zhenxia Zhang Revised by Jiying Zhao (2015w)
JAVA Socket Programming Source: by Joonbok Lee, KAIST, 2003.
Greg Jernegan Brandon Simmons. The Beginning…  The problem Huge demand for internet enabled applications and programs that communicate over a network.
CS4273: Distributed System Technologies and Programming I Lecture 5: Java Socket Programming.
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.
Appendix F: Network Programming in Java ©SoftMoore ConsultingSlide 1.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 12 Communicating over.
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.
Socket Programming in Java CS587x Lecture 4 Department of Computer Science Iowa State University.
Object Oriented Programming in Java Lecture 16. Networking in Java Concepts Technicalities in java.
© Amir Kirsh Java Networking Written by Amir Kirsh.
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
Java Socket programming. Socket programming with TCP.
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.
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.
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,
© 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.
CSI 3125, Preliminaries, page 1 Networking. CSI 3125, Preliminaries, page 2 Inetaddress Class When establishing a connection across the Internet, addresses.
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.
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.
Networking Code CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
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.
Java Networking(I) 曾俊雄. Overview Java is a very good choice for networking programming. Client : – Socket – Applet – Java Web Start – Java Network Launch.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Echo Networking COMP
SOCKET PROGRAMMING.
Java 13. Networking public class SumTest {
Echo Networking COMP
Lecture 21 Sockets 1 (Not in D&D) Date.
CSE 341, S. Tanimoto Java networking-
RADE new features via JAVA
Networking with Java 2.
PRESENTED To: Sir Abid………. PRESENTED BY: Insharah khan………. SUBJECT:
„Networking”.
Implementação de Socket UDP e TCP em Java
Distributed Computing
Chapter 2: Application layer
Programming TCP Sockets
Presentation transcript:

© Amir Kirsh Java Networking Written by Amir Kirsh, Edited by Liron Blecher

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

3 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 } }

4 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

6 Simple TCP Echo Client String line = ""; try (Socket socket = new Socket("localhost", 7000)) { BufferedReader inputStream = new BufferedReader(new InputStreamReader(socket.getInputStream())); PrintStream outputStream = new PrintStream(socket.getOutputStream()); BufferedReader userInput = new BufferedReader(new InputStreamReader(System.in)); while (!line.equals("!")) { line = userInput.readLine(); outputStream.println(line); System.out.println(inputStream.readLine()); }

7 Simple TCP Echo Client – cont’ public static void main(String[] args) { try { … } catch (Exception e) { System.err.println(e); } }

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

9 Simple TCP Echo Server String line = ""; try (ServerSocket server = new ServerSocket(7000)) { Socket socket = server.accept(); // blocking BufferedReader inputStream = new BufferedReader(new InputStreamReader(socket.getInputStream())); PrintStream outputStream = new PrintStream(socket.getOutputStream()); while (!line.equals("!")) { line = inputStream.readLine(); outputStream.println(line); System.out.println(line); }

10 Simple TCP Echo Server – cont’ public static void main(String[] args) { try { … } catch (Exception e) { System.err.println(e); } }

DEMO examples.streams.simple 11

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

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

DEMO examples.streams.advanced 14