Network-based Applications. Pavani Diwanji David Brown JavaSoft



Similar documents
SSC - Communication and Networking Java Socket Programming (II)

Socket Programming in Java

NETWORK PROGRAMMING IN JAVA USING SOCKETS

NETWORKING FEATURES OF THE JAVA PROGRAMMING LANGUAGE

Network Communication

The difference between TCP/IP, UDP/IP and Multicast sockets. How servers and clients communicate over sockets

Socket Programming. Announcement. Lectures moved to

Intranet, Extranet, Firewall

Lecture 2-ter. 2. A communication example Managing a HTTP v1.0 connection. G.Bianchi, G.Neglia, V.Mancuso

Socket-based Network Communication in J2SE and J2ME

Learning Outcomes. Networking. Sockets. TCP/IP Networks. Hostnames and DNS TCP/IP

Java Network. Slides prepared by : Farzana Rahman

Network Programming. Writing network and internet applications.

Transport layer protocols. Message destination: Socket +Port. Asynchronous vs. Synchronous. Operations of Request-Reply. Sockets

Java Programming: Sockets in Java

Using TestLogServer for Web Security Troubleshooting

Socket Programming. A er learning the contents of this chapter, the reader will be able to:

Application Development with TCP/IP. Brian S. Mitchell Drexel University

DNS: Domain Names. DNS: Domain Name System. DNS: Root name servers. DNS name servers

Chapter 4 Security and Firewall Protection

Chapter 3. Internet Applications and Network Programming

Pass Through Proxy. How-to. Overview:..1 Why PTP?...1

About Firewall Protection

Web. Services. Web Technologies. Today. Web. Technologies. Internet WWW. Protocols TCP/IP HTTP. Apache. Next Time. Lecture # Apache.

Data Communication & Networks G

Creating a Simple, Multithreaded Chat System with Java

Lesson: All About Sockets

Firewall Defaults, Public Server Rule, and Secondary WAN IP Address

Network Layers. CSC358 - Introduction to Computer Networks

Transport Layer Services Mul9plexing/Demul9plexing. Transport Layer Services

Review: Lecture 1 - Internet History

Encapsulating Voice in IP Packets

How to Configure Captive Portal

Layer Four Traceroute (and related tools) A modern, flexible path-discovery solution with advanced features for network (reverse) engineers

Question1-part2 What undesirable consequences might there be in having too long a DNS cache entry lifetime?

1 Introduction: Network Applications

F-SECURE MESSAGING SECURITY GATEWAY

Abhijit A. Sawant, Dr. B. B. Meshram Department of Computer Technology, Veermata Jijabai Technological Institute

ICOM : Computer Networks Chapter 6: The Transport Layer. By Dr Yi Qian Department of Electronic and Computer Engineering Fall 2006 UPRM

Assignment 4 Solutions

IP Network Layer. Datagram ID FLAG Fragment Offset. IP Datagrams. IP Addresses. IP Addresses. CSCE 515: Computer Network Programming TCP/IP

Using IPM to Measure Network Performance

Building a Multi-Threaded Web Server

Network Programming using sockets

LifeSize UVC Video Center Deployment Guide

Skywire TCP Socket Examples

CS101 Lecture 19: Internetworking. What You ll Learn Today

Tue Apr 19 11:03:19 PDT 2005 by Andrew Gristina thanks to Luca Deri and the ntop team

PANDORA FMS NETWORK DEVICES MONITORING

Blue Coat Security First Steps Solution for Streaming Media

Owner of the content within this article is Written by Marc Grote

IP - The Internet Protocol

Question: 3 When using Application Intelligence, Server Time may be defined as.

Computer Networking LAB 2 HTTP

Configuring SonicWALL TSA on Citrix and Terminal Services Servers

Computer Networks. Introduc)on to Naming, Addressing, and Rou)ng. Week 09. College of Information Science and Engineering Ritsumeikan University

Chapter 6 Virtual Private Networking Using SSL Connections

Chapter 8 Router and Network Management

Application. Transport. Network. Data Link. Physical. Network Layers. Goal

TCP/IP Fundamentals. OSI Seven Layer Model & Seminar Outline

First Workshop on Open Source and Internet Technology for Scientific Environment: with case studies from Environmental Monitoring

PANDORA FMS NETWORK DEVICE MONITORING

Securing Networks with PIX and ASA

Dissertation Title: SOCKS5-based Firewall Support For UDP-based Application. Author: Fung, King Pong

Limi Kalita / (IJCSIT) International Journal of Computer Science and Information Technologies, Vol. 5 (3), 2014, Socket Programming

CISC 4700 L01 Network & Client- Server Programming Spring Harold, Chapter 8: Sockets for Clients

HOW TO CONFIGURE PASS-THRU PROXY FOR ORACLE APPLICATIONS

Final for ECE374 05/06/13 Solution!!

Protocolo HTTP. Web and HTTP. HTTP overview. HTTP overview

What communication protocols are used to discover Tesira servers on a network?

IP Routing Features. Contents

Chapter 4 Firewall Protection and Content Filtering

DEPLOYMENT GUIDE Version 1.1. DNS Traffic Management using the BIG-IP Local Traffic Manager

Chapter 4 Firewall Protection and Content Filtering

Cisco NetFlow TM Briefing Paper. Release 2.2 Monday, 02 August 2004

Cisco IOS Flexible NetFlow Command Reference

Network Programming TDC 561

Course Overview: Learn the essential skills needed to set up, configure, support, and troubleshoot your TCP/IP-based network.

Computer Networks. Lecture 7: Application layer: FTP and HTTP. Marcin Bieńkowski. Institute of Computer Science University of Wrocław

12. Firewalls Content

Socket programming. Complement for the programming assignment INFO-0010

Per-Flow Queuing Allot's Approach to Bandwidth Management

NetFlow Tracker Overview. Mike McGrath x ccie CTO mike@crannog-software.com

SuperLumin Nemesis. Administration Guide. February 2011

Oracle Discoverer 4i Plus Firewall and SSL Tips. An Oracle White Paper February 2002

P and FTP Proxy caching Using a Cisco Cache Engine 550 an

Building a Scale-Out SQL Server 2008 Reporting Services Farm

Serializing Data with Protocol Buffers. Vinicius Vielmo Cogo Smalltalks, DI, FC/UL. February 12, 2014.

Table of Contents. Cisco Using the Cisco IOS Firewall to Allow Java Applets From Known Sites while Denying Others

Websense Web Security Gateway: What to do when a Web site does not load as expected

Astaro Security Gateway V8. Remote Access via SSL Configuring ASG and Client

Chapter 4 Firewall Protection and Content Filtering

Rapid Assessment Key v2 Technical Overview

Unix System Administration

Chapter 3. TCP/IP Networks. 3.1 Internet Protocol version 4 (IPv4)

DEPLOYMENT GUIDE Version 1.1. Configuring BIG-IP WOM with Oracle Database Data Guard, GoldenGate, Streams, and Recovery Manager

A host-based firewall can be used in addition to a network-based firewall to provide multiple layers of protection.

ACCREDITED SOLUTION. EXPLORER Core FTP

Transcription:

Network-based Applications Pavani Diwanji David Brown JavaSoft

Networking in Java Introduction Datagrams, Multicast TCP: Socket, ServerSocket Issues, Gotchas URL, URLConnection Protocol Handlers Q & A

InetAddress InetAddress Object: address, family Name service methods getbyname getallbyname (multihomed hosts) Cache the name, address mapping

Datagrams Packet oriented: send and receive No connection setup/teardown overhead Datagrams can get lost in the internet Reliability does not come for free Latency: retransmissions Bandwidth: duplicates, forward error correction Example- Video: a frame is lost!

java.net.datagrampacket Represents datagram packet Data buffer, packet length, IP address, port Sender creates a DatagramPacket with the data, length, destination IP address and port number

DatagramPacket (cont.) On receiving side: application allocates a byte buffer for receiving the packet and passes it to the DatagramPacket constructor Receiving buffer can be reused over multiple datagram receives

DatagramSocket Class DatagramSocket { public DatagramSocket(); public DatagramSocket(int port); public void send(datagrampacket p); public void synchronized recieve(datagrampacket p);... }

Simple Datagram Client import java.net.datagramsocket; import java.net.datagrampacket; class DatagramClient { DatagramSocket s = new DatagramSocket(); DatagramPacket dp = formatpacket(destinationhost, port); s.send(dp);... s.close(); }

Simple Datagram Server import java.net.datagramsocket; import java.net.datagrampacket; class DatagramServer {... DatagramSocket s = new DatagramSocket(); System.out.println( Server receiving on port: + s.getlocalport()) DatagramPacket dp = new DatagramPacket(buf, length); s.receive(dp);... s.close(); }

IP Multicast Deliver a packet to a set of destinations Destination set is identified by a single group address. Membership can change over time More efficient than unicasting seperate copies to all destinations Logical/location independent addressing RFC s 966, 1112

IP Multicast (cont.) Addressing Range: 224.x.x.x - 239.x.x.x Addresses assigned by hand! Scoped Multicasting time-to-live (TTL) field TTL=0: same host TTL=1: same subnet TTL=255: unrestricted

Useful Multicast Examples Querying a distributed file store, when the actual location of data is unknown Location Service: locate objects on the net Sending video over the internet: MBONE Real-time networked games

Multicast Class in Java sun.net.multicastsocket Extends java.net.datagramsocket New methods: joingroup(inetaddress mcast); leavegroup(inetaddress mcast); send(datagrampacket dp, byte ttl);

Simple Multicast Example import sun.net.multicastsocket; class VideoReceiver { // listen to the video on the MBONE InetAddress receivers = InetAddress.getByName( 224.1.2.3 ); MulticastSocket mcast = new MulticastSocket(); mcast.joingroup(receivers);. mcast.receive(packet); // Receive multicast packet. mcast.leavegroup(receivers); // clean up when finished mcast.close(); }

TCP Socket Classes Socket: Client Endpoint for doing TCP based communication ServerSocket: Server endpoint for doing TCP based communication SocketImpl: Site-specific implementation of sockets (e.g. SOCKS, Kona) PlainSocketImpl: used by default

Socket, ServerSocket Connect to destination by: Constructing a socket given the InetAddress and port. read/write done through: Socket.getInputStream(), Socket.getOutputStream() ServerSocket.accept(): Blocks until a client asks to connect Returns a new client socket handle

Keep in Mind Java Applets!= Java Applications Applets are restricted in what they can do. Security manager in the browser restricts who Applets are allowed to talk to: checkconnect, checkaccept, checklisten... No restrictions, though on Network based Applications: write native code to do whatever they want!

Issues SecurityManager Checks in datagram and multicast receive: Can getting data hurt? Multicast Security Group address-based TTL-based

Issues Name service is not secure! Firewalls, Proxies: a necessary evil? Firewalls only let HTTP traffic through. Name resolution within firewall Can resolve an external hostname Cannot resolve an external hostname

Issues Stamp where the applets came from, and never call the name service again! Where did the applet come from, if proxy is in the picture? Applet Host network Proxy Client Host Firewall

Gotchas Timers: ms level granularity, relative. Need finer grained (us) timers Absolute timers No Poll/Select Setting socket options

Gotchas Timeouts on read/write not available Use of synchronized buffered streams PrintStream eats exceptions! Check explictly for errors

Conclusions Sample Code Examples: http://www.javasoft.com/people/pavani Questions?

Network-based Applications: Extending java.net.url* David Brown JavaSoft

The Classes URL URLStreamHandler URLConnection URLStreamHandlerFactory

Why Extend the URL Classes? Your own web protocols Your own content handling Link legacy servers to web Simple, small, powerful Leverage Java More resources than applets

java.net.url Constructed from String new URL( http://www.javasoft.com ); Knows its own URLStreamHandler Data members: String protocol; String host; int port; String file; URLStreamHandler handler;

URLStreamHandler Abstract class One for each URL protocol Create URLConnection given a URL URLConnection openconnection(url); Parse a URL in protocol-specific way Unparse a URL back to String String toexternalform(url u);

URLConnection Abstract class No public constructor Instantiable only by StreamHandler Can dynamically plug in content handlers protected URLConnection(URL u); String getcontenttype(); ContentHandler getcontenthandler(); setcontenthandlerfactory();

URLStreamHandlerFactory One way to add protocol handlers Interface one method: URLStreamHandler createurlstreamhandler(string protocol); Set the Factory in class URL: URL.setURLStreamHandlerFactory()

CGI POST by URLConnection HttpURLConnection can POST URL url = new URL( http://java.sun.com/cgi-bin/reverse ); URLConnection conn = url.openconnection(); PrintStream ps = new PrintStream(conn.getOutputStream()); ps.println( string=stringtoreverse ); ds = new DataInputStream(conn.getInputStream()); String result = ds.readline(); /* result should be esreverotgnirts */ Applets can connect home from behind firewall

Restrictions/Gotcha s Only certain sequences of I/O allowed Interpreted as POST: get output [write output], get input [read input] get output [write output] Interpreted as GET: get input [read input]

Restrictions/Gotcha s Disallowed: get input [read input], get output [write output], HttpURLConnection has state Why? HTTP 1.0 vs 1.1 No KEEPALIVE/persistent connections

Simple Example: Finger Protocol A protocol for fingering users URL finger:brown@monkey,pavani@sai Produces output like: Finger data for brown@monkey : Login Name TTY Idle When brown Dave Brown console 0:18 Wed 18:53 Finger data for pavani@sai : Login Name TTY Idle When pavani Pavani Diwanji console 0:13 Tue 9:54

The (web) Finger Protocol browser host finger response host URLConnection network host Gather data from multiple connections

Class Relationships URLConnection URL url getcontent() URL openconnection() URLStreamHandler handler URLStreamHandler openconnection(url) Legend: Abstract class Abstract method() Concrete class Concrete method() Pseudo-code Contains Instantiates FingerURLConnection getcontent() gather finger data; format HTML-style; return output; FingerHandler openconnection(url) Inheritance

Step 1: Create a New URL finger:joe@dinosaur,brown@monkey Is there a finger protocol handler? Ask the handler to parse the URL Default does usual HTTP parsing: < protocol>://<host>/<file>

Step 2: Connect the URL URL.openConnection(): Type of URLConnection delegated to URL s handler Here s the extensiblity: Data gathering done by an instance of FingerURLConnection Format raw data for browser viewing

What Must URLConnection Do? URLConnection defines ~53 methods Only override 4: FingerURLConnection(URL) String getcontenttype(): return text/html ;

What Must URLConnection Do? Object getcontent(): Create a StringBuffer; for each entry in list { Connect to host; finger user; append finger result to StringBuffer (with HTML formatting); } return new String(StringBuffer); InputStream getinputstream(): return new StringBufferInputStream((String)getContent( ));

Interesting Protocols Newsgroup binary formatter listen:alt.binaries.sounds.birds Meta search engine search://yahoo,lycos,webcrawler/java AND protocol Filter protocol - filtered HTML Database queries jdbc://<query-string>

Sample Code Available http://www.javasoft.com/people/ brown Questions/Flames? brown@monkey.eng.sun.com