Basic Java Network Programming. CS211 July 30 th, 2001

Similar documents
Networking and Security

JAVA SOCKET PROGRAMMING

Advanced Java Programming. Networking

CSCD 330 Network Programming Spring 2018

CSCD 330 Network Programming Spring 2018

Network Programming. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff

Lecture 3. Java Socket Programming. TCP, UDP and URL

CSCD 330 Network Programming Winter 2019

CPSC 441 UDP Socket Programming. Department of Computer Science University of Calgary

Socket 101 Excerpt from Network Programming

JAVA - NETWORKING (SOCKET PROGRAMMING)

Outlines. Networking in Java. Internet hardware structure. Networking Diagram. IP Address. Networking in Java. Networking basics

Networking Basics. network communication.

Networking. Lecture 25 ish? COP 3252 Summer July 11, 2017

JAVA Network API. 2 - Connection-Oriented vs. Connectionless Communication

Java Networking (sockets)

Internet Protocol. Chapter 5 Protocol Layering. Juho Kim Graduate School of Information & Technology Sogang University

Distributed Systems Recitation 2. Tamim Jabban

Info 408 Distributed Applications programming 2 nd semester of 2017/2018 Credits: 5 Lecturer: Dr. Antoun Yaacoub

Communication in Distributed Systems: Sockets Programming. Operating Systems

Lecture 3: Socket Programming

Principles, Models and Applications for Distributed Systems M

Distributed Systems Recitation 2. Tamim Jabban

Unit 1 Java Networking

Introduction to Sockets 9/25/14

Chapter 2 Application Layer

CS September 2017

COMP 213. Advanced Object-oriented Programming. Lecture 20. Network Programming

Networking: IPv6, UDP and TCP. Network Programming in Java UDP and TCP

Chapter 2 Application Layer

Networking with java (socket programming) a brief study

Assignment 1. Due date February 6, 2007 at 11pm. It must be submitted using submit command.

Java for Interfaces and Networks

Principles of Software Construction. Introduction to networks and distributed systems School of Computer Science

Network Programming Benoît Garbinato

Previous lecture: threads G51PRG: Introduction to Programming Second semester Lecture 12 URL

CPSC 441 Tutorial - 11 UDP Socket Programming Department of Computer Science University of Calgary

Internet Technology 2/7/2013

Outline of Topics. UDP Socket Java Programming. Multicast in Java. Real-time protocol (RTP) XMPP and Jingle protocols. Java I/O and New IO (NIO)

Java for Interfaces and Networks (DT3029)

Introduction to Socket Programming

Java Socket Workshop. July Purpose of this workshop:

CS 351 Design of Large Programs Sockets Example

Interprocess Communication

OBJECT ORIENTED PROGRAMMING

Chapter 2 outline. 2.1 Principles of app layer protocols

CPSC 441 Assignment-3 Discussion. Department of Computer Science University of Calgary

SERVER/CLIENT NETWORKING AT JAVA PLATFORM

A socket is a software endpoint that establishes bidirectional communication between a server program and one or more client programs.

Transport layer protocols. Lecture 15: Operating Systems and Networks Behzad Bordbar

Joseph Faber Wonderful Talking Machine (1845)

AJP: Chapter 2 Networking: 18 marks

Chapter 9: UDP sockets & address conversion function

Java.net Package and Classes(Url, UrlConnection, HttpUrlConnection)

CN1047 INTRODUCTION TO COMPUTER NETWORKING CHAPTER 6 OSI MODEL TRANSPORT LAYER

Networking Fundamentals

Chapter 11. Application-Layer Elements Ports

Unit 9: Network Programming

BSc (Hons) Computer Science with Network Security. Examinations for 2017 / Semester 2. Resit Examinations for BCNS/15A/FT

Socket Programming(TCP & UDP) Sanjay Chakraborty

Framework. Set of cooperating classes/interfaces. Example: Swing package is framework for problem domain of GUI programming

CS 355. Computer Networking. Wei Lu, Ph.D., P.Eng.

CSS 533 Program 2: Distributed Java Space Servers Professor: Munehiro Fukuda Due date: see the syllabus

Internet Protocol (IP) TCP versus UDP

Chapter 2: outline. 2.1 principles of network applications. 2.6 P2P applications 2.7 socket programming with UDP and TCP

Distributed Systems. 3. Access to the Transport Layer. Werner Nutt

The TCP Protocol Stack

Lab 1 : Java Sockets

CSC 4900 Computer Networks: P2P and Sockets

Distributed Systems COMP 212. Lecture 8 Othon Michail

TCP and Concurrency. The third assignment at DA

Applet. 1. init (): called once by the applet containers when an applet is loaded for execution.

TCP connections. Fundamentals of Internet Connections Objectives. Connect to an Echo port. java.net.socket

Today. cisc3120-fall2012-parsons-lectiv.2 2

31 Network Programming

CSE 461 Module 11. Connections

An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a

Java A.1 TCP/IP TCP. TCP_RO.java import java.net.*; import java.io.*;

C18: Network Fundamentals and Reliable Sockets

SOCKETS. COMP750 Distributed Systems

Construction d Applications Réparties / Master MIAGE

The ASP Virtual Networking (VNET) Component. 23 July Abstract

Java Support for developing TCP Network Based Programs

protocols September 15,

Software Practice 1 - Socket

Java networking using sockets

World Scientific Research Journal (WSRJ) ISSN: The Implementation of Tcp Socket Programming based on Java

Info 408 Distributed Applications programming 2 nd semester of Credits: 5 Lecturer: Dr. Antoun Yaacoub

Chapter 4: Processes

Java Technologies. Lecture VII. Valdas Rapševičius. Vilnius University Faculty of Mathematics and Informatics

Layer 4 - Transport Layer. What do we need a Transport Layer for? Transport Protocols in the TCP/IP Reference Model. The Transport Layer TCP and UDP

public static void main(string[] args) throws IOException { sock = new Socket(args[0], Integer.parseInt(args[1]));

Layer 4 - Transport Layer

Interprocess Communication

Assignment 2 CISC 650 Computer Networks Fall 2016 Due Date: 10/9/ :59PM ET Total Points: 100

Java Programming Language Advance Feature

UDP Sockets TCP guarantees the delivery of packets and preserves their order on destination. Sometimes these features are not required, since they do

Communication Paradigms

Introduction to Network Programming using Java

Reliability is an issue. You cannot afford to have any of the data lost or re-ordered.

Transcription:

Basic Java Network Programming CS211 July 30 th, 2001

The Network and OSI Model

IP Header TCP Header

TCP/IP: A Paradox

TCP Connection Oriented and Connectionless Protocols Reliable: no loss, or duplication, or out of order End-to-end Connection Oriented: congestion control, flow control UDP & IP Unreliable Datagram Connectionless

InetAddress Class represents an IP address. numeric addresses <---> host names InetAddress utopia, duke; try { utopia=inetaddress.getbyname("utopia.poly.edu"); duke=inetaddress.getbyname("128.238.2.92"); } catch (UnknownHostException e) { System.err.println(e); } public static InetAddress[] getallbyname(string host) throws UnknownHostException public static InetAddress getlocalhost() throws UnknownHostException

URL class create new URLs parse the different parts of a URL, namely: the protocol the authority user info: user name, password host name or address port the path, a.k.a. file the ref, a.k.a. section or anchor the query string get an input stream from a URL so you can read data from a server get content from the server as a Java object

Webcat.java: Reading data from a URL public class Webcat { public static void main(string[] args) { for (int i = 0; i < args.length; i++) { } } try { URL u = new URL(args[i]); BufferedReader br = new BufferedReader( new InputStreamReader (new InputStream( u.openstream()))); String theline; while ((theline = br.readline())!= null) { System.out.println(theLine); } } catch (IOException e) { System.err.println(e); } }

Socket Communication Client Server Paradigm

TCP Sockets Server socket class: ServerSocket wait for requests from clients. after a request is received, a client socket is generated. Client socket class: Socket an endpoint for communication between two apps/applets. obtained by contacting a server generated by the server socket Communication is handled by input/output streams. Socket provides an input and an output stream.

TCP Sockets cont. public Socket(String host, int port, InetAddress localaddr, int localport) public Socket(InetAddress address, int port, InetAddress localaddr, int localport) public ServerSocket(int port, int backlog, InetAddress bindaddr)

Summary: TCP Server 1. Create the server socket and begin listening. 2. Call the accept() method to get new connections. 3. Create input and output streams for the returned socket. 4. Conduct the conversation based on the agreed protocol. 5. Close the client streams and socket. 6. Go back to step 2 or continue to step 7. 7. Close the server socket

Datagram Sockets same class is used for both client and server halves public DatagramSocket (int port, InetAddress laddr) DatagramSocket serversocket = new DatagramSocket( 4545 ); DatagramSocket clientsocket = new DatagramSocket(); public DatagramPacket(byte[] buf, int offset, int length, InetAddress address, int port) DatagramPacket sendpacket = new DatagramPacket( sendbuf, sendbuf.length, addr, port);

Summary: UDP Server 1. Create the datagram socket on a specific port. 2. Call receive() to wait for incoming packets. 3. Respond to received packets according to the agreed protocol. 4. Go back to step 2 or continue to step 5. 5. Close the datagram socket.

Multicast A multicast address is a class D address in the range 224.0.0.1 to 239.255.255.255, inclusive

Multicast Sockets Multicast Sockets use Datagram Packets BIG difference lies in Multicast's capability to transmit to all listening hosts simultaneously. Downside is the lack of support for multicast routing. Most routers still don t forward multicast packets. Notion of Groups: Join and leave groups.

Applets public void init(): To initialize the applet each time it's loaded (or reloaded). public void start(): To start the applet's execution, such as when the applet's loaded or when the user revisits a page that contains the applet. public void stop(): To stop the applet's execution, such as when the user leaves the applet's page or quits the browser. public void destroy(): To perform a final cleanup in preparation for unloading.

Applet Example import java.applet.*; import javax.swing.*; public class HTMLLabelApplet extends JApplet { public void init() { JLabel thetext = new JLabel( "<html>hello! This is a multiline label with <b>bold</b> " + "and <i>italic</i> text. <P> " + "It can use paragraphs, horizontal lines, <hr> " + "<font color=red>colors</font> " + "and most of the other basic features of HTML 3.2</html>"); this.getcontentpane().add(thetext); } }

Applet Tags <APPLET CODE=AppletSubclass.class WIDTH=anInt HEIGHT=anInt> <PARAM NAME=parameter1Name VALUE=aValue> <PARAM NAME=parameter2Name VALUE=anotherValue> </APPLET> e.g. <APPLET CODE="Animator.class" WIDTH=460 HEIGHT=160> <PARAM NAME="imageSource" VALUE="images/Beans"> <PARAM NAME="backgroundColor" VALUE="0xc0c0c0"> <PARAM NAME="endImage" VALUE=10> <PARAM NAME="soundSource" VALUE="audio"> <PARAM NAME="soundtrack" VALUE="spacemusic.au"> <PARAM NAME="sounds" VALUE="1.au 2.au 3.au 4.au 5.au 6.au 7.au 8au 9.au 0.au" > <PARAM NAME="pause" VALUE=200>... </APPLET>

Applet Example

Applet Security Can open a socket only to the host name from which it was loaded. Other connections results in a SecurityException. Datagram sockets don't open connections. Hence when an inbound packet is received, the host name is checked. Multicast sockets are disallowed.