Java Programming Unit 10. Stock Price Quotes with URL, Sockets, and RMI



Similar documents
Division of Informatics, University of Edinburgh

Java Network. Slides prepared by : Farzana Rahman

Lesson: All About Sockets

Transport Layer Services Mul9plexing/Demul9plexing. Transport Layer Services

Network Communication

Creating a Simple, Multithreaded Chat System with Java

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

Socket = an interface connection between two (dissimilar) pipes. OS provides this API to connect applications to networks. home.comcast.

Socket Programming. Announcement. Lectures moved to

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

Network/Socket Programming in Java. Rajkumar Buyya

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

Building a Multi-Threaded Web Server

Lab Configure and Test Advanced Protocol Handling on the Cisco PIX Security Appliance

Real-time Device Monitoring Using AWS

Programmation RMI Sécurisée

BlackBerry Enterprise Service 10. Version: Configuration Guide

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

NetFlow Analytics for Splunk

Intranet, Extranet, Firewall

Network Security. Computer Security & Forensics. Security in Compu5ng, Chapter 7. l Network Defences. l Firewalls. l Demilitarised Zones

Report of the case study in Sistemi Distribuiti A simple Java RMI application

Using SQL-server as database engine

!"# $ %!&' # &! ())*!$

Ruckus Wireless access point set up from an Audio Everywhere streaming perspec;ve. Lance Glasser 6 June 2015

GV-iView HD V1 for ipad

Firewalls and Software Updates

CA CPT CICS Programmers Toolkit for TCP/IP r6.1

COM 440 Distributed Systems Project List Summary

IT6503 WEB PROGRAMMING. Unit-I

EXPLORER. TFT Filter CONFIGURATION

Java Application Development using Eclipse. Jezz Kelway Java Technology Centre, z/os Service IBM Hursley Park Labs, United Kingdom

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

Network-based Applications. Pavani Diwanji David Brown JavaSoft

Introduction to Java. Module 12: Networking (Java Sockets) Prepared by Costantinos Costa for EPL 233. ΕΠΛ233 Αντικειμενοστρεφής Προγραμματισμός 1

Index. AdWords, 182 AJAX Cart, 129 Attribution, 174

Chapter 8 Router and Network Management

String sentence = new String(receivePacket.getData()); InetAddress IPAddress = receivepacket.getaddress(); int port = receivepacket.

Learning Remote Control Framework ADD-ON for LabVIEW

WORKING WITH WINDOWS FIREWALL IN WINDOWS 7

Network Programming using sockets

Onset Computer Corporation

Assignment 4 Solutions

Managing Qualys Scanners

COMMANDS 1 Overview... 1 Default Commands... 2 Creating a Script from a Command Document Revision History... 10

Adaptive Log Exporter Users Guide

WebSocket Server. To understand the Wakanda Server side WebSocket support, it is important to identify the different parts and how they interact:

Datagram. Datagram SyslogAgent manual. Version 3.6

LifeSize UVC Video Center Deployment Guide

Overview - Using ADAMS With a Firewall

Enter Here -> Directory Submitter Software For One > Visit Here <

Design Notes for an Efficient Password-Authenticated Key Exchange Implementation Using Human-Memorable Passwords

Overview - Using ADAMS With a Firewall

KB Microsoft Network Security Hotfix Checker (Hfnetchk.exe) Tool Is Available

Advanced Event Viewer Manual

Introduction to BlackBerry Development using Java ME. Presented by: Sean Fenton Technical Channel Manager RIM (Research in Motion )

An Overview of Java. overview-1

Avaya IP Office SIP Trunk Configuration Guide

Volume SYSLOG JUNCTION. User s Guide. User s Guide

Bridgit Conferencing Software: Security, Firewalls, Bandwidth and Scalability

Port Scanning and Vulnerability Assessment. ECE4893 Internetwork Security Georgia Institute of Technology

This document explains how to enable the SIP option and adjust the levels for the connected radio(s) using the below network example:

Firewall Stateful Inspection of ICMP

IBM Security QRadar Vulnerability Manager Version User Guide

Developing Web Services with Eclipse

Applets, RMI, JDBC Exam Review

Passwords are for Chumps

Building Web Services with Apache Axis2

NetSpective Global Proxy Configuration Guide

USER GUIDE. Diagnostic Web Server FW ver BrightSign, LLC Lark Ave., Suite B Los Gatos, CA

HP Device Manager 4.6

Kaseya Fundamentals Workshop DAY THREE. Developed by Kaseya University. Powered by IT Scholars

No Cloud Allowed. Denying Service to DDOS Protection Services

Agenda. Network Programming and Java Sockets. Introduction. Internet Applications Serving Local and Remote Users

Debugging Java Applications

GV-AView for Android Smartphones & Tablets

How To Improve Performance On An Asa 9.4 Web Application Server (For Advanced Users)

ThinPoint Quick Start Guide

How to Enable Remote JMX Access to Quartz Schedulers. M a y 1 2,

umobilecam Setup Guide All-in-One Mobile Surveillance for Android, ios, Mac, Windows Webcam, IP camera (version 1.0)

S y s t e m A r c h i t e c t u r e

Decryption. Palo Alto Networks. PAN-OS Administrator s Guide Version 6.0. Copyright Palo Alto Networks

Installing NetSupport School for use with the NetSupport School Student extension for Google Chrome

Building Java Servlets with Oracle JDeveloper

DiskPulse DISK CHANGE MONITOR

Lutron Home Control Remote Access FAQ

Consuming a Web Service(SOAP and RESTful) in Java. Cheat Sheet For Consuming Services in Java

IBM Operational Decision Manager Version 8 Release 5. Getting Started with Business Rules

KonyOne Server Prerequisites _ MS SQL Server

Configuring Nex-Gen Web Load Balancer

Enterprise Manager. Version 6.2. Installation Guide

1 Introduction: Network Applications

LiveStreamingCDN Producer User s Guide

Using Process Monitor

Internet Technologies. World Wide Web (WWW) Proxy Server Network Address Translator (NAT)

Server Configuration and Customization Guide. Operations Center 5.0

Magnet Voice Windows PC Softphone Installation

Transcription:

Java Programming Unit 10 Stock Price Quotes with URL, Sockets, and RMI

GeFng Stock Quotes From Yahoo! 1. Visit hjp://finance.yahoo.com, enter AAPL - the symbol of the Apple s stock, and press the bujon Get Quotes. Note the URL. Change it to hjp://finance.yahoo.com/q?s=aapl 2. To get the price quote programma&cally create an instance of the URL object and open the stream: url = new URL( http://finance.yahoo.com/q?s=aapl );! InputStream in = url.getinputstream();! BufferedReader buff= new BufferedReader(new InputStreamReader(in));!! One way of gefng the stock info from Yahoo! is to read the en^re Web page: String thewholepage;! Srting txt;! while (txt =buff.readline()!= null ){! thewholepage=thewholepage + txt;! } and then parse it trying to find the fragment with the AAPL price.

An alterna^ve URL for stock quotes The previous solu^on produces lots of text to filter out. Here you can get the quotes for AAPL or any other stock symbol in the CSV format: hjp://quote.yahoo.com/d/quotes.csv?s=aapl&f=sl1d1t1c1ohgv&e=.csv The classes StringTokenizer or Scanner can help you in parsing the received String with comma- separated values. The textbook has a sample code (pg. 191 193) that uses the stock symbol MOT, which used to represent Motorola. Since the MOT stock symbol has been recently modified, use MSI for Motorola or any other valid stock symbol, e.g. AAPL for Apple.

Walkthrough 1 Review with the instructor the code of the program StockQuote.java from Eclipse project Lesson18 Go to the Eclipse menu Run Configura^ons and enter AAPL in the field Program Arguments Run the program and observe the current price of the stock Change the stock symbol to be IBM and re- run the program to see the latest price of IBM stock Run the same program through a debugger placing a breakpoint at line 26. Debug the program and watch the work of the class StringTokenizer!

Programming Sockets

What s Socket The package java.net includes classes Socket and ServerSocket. A socket is a connec%on end- point in IP networking. The TCP/IP protocol maintains a socket connec^on for the whole period of communica^on, while UDP is a connec^onless protocol, which sends data in small chunks called datagrams. The socket address is a pairof IP address and port. An instance of the ServerSocket class becomes a server that listens to the specified port for requests.

Sockets: the Client and the Server The following two lines create a server that is listening to port 3000: ServerSocket serversocket = new ServerSocket(3000); Socket client = serversocket.accept(); The client program creates an instance of the class Socket poin^ng at the computer/port on which the ServerSocket is running: Socket clientsocket = new Socket("124.67.98.101", 3000);! WebSocket is an new HTML5 standard of communica^on over the Internet. More details here: http://enterprisewebbook.com/ch8_websockets.html

GeFng Stock Quotes with Sockets JVM 1 (the server): 1. Start the ServerSocket on some port new ServerSocket(3000);! 2. Put it in a listening mode with accept(). 3. Process the request and return the result to the client via the stream. JVM 2 (the client): 1. Connect to the server socket by instan^a^ng the class Socket clientsocket = new Socket( 124.67.98.101, 3000);! 2. Get the reference to the server s stream outbound = clientsocket.getoutputstream();! 3. Send your requests to this stream. 4. Process server s responses

Walkthrough 2 Review with instructor the code of the program StockQuoteServer and Client from Eclipse project Lesson18 Follow the instruc^ons from the TRY IT sec^on to Lesson 18 to test the client- server communica^ons using sockets.

Non- Blocking Sockets If our stock server needs to process mul^ple requests, the StockQuoteServer would need to create a new thread for each request. Each thread introduces an overhead limi^ng the number requests that can be processed concurrently. The package java.nio includes a number of classes that support non- blocking i/o in general and non- blocking sockets in par^cular. which allows i/o communica^ons on the socket channel without blocking the processes using it. You can read a short tutorial on non- blocking I/O by Jacob Jenkov: hjp://tutorials.jenkov.com/java- nio/index.html

Remote Method Invoca^on (RMI) RMI allows JVMs communicate with each other. With sockets, the Java client was directly connec^ng to Java server running on a different JVM. With RMI, Java client will make a method call that looks as if this method is running in the same JVM, but it s not. Only a proxy (a stub) of the remote method exists in the client s JVM. (c) Yakov Fain 2013

Finding Remote Objects RMI clients find remote services by using a naming service, which must run on a known host and port number. The RMI server can start its own registry that offers naming services for RMI clients. The behavior of the registry is defined by the interface java.rmi.registry.registry By default, the RMI registry runs on port 1099 The client obtains a reference to a remote object by looking up its name in the registry. This lookup returns to the client a remote reference a.k.a. stub. The method lookup() takes the service name URL as an argument in the following format: rmi://<host_name>[:<name_service_port>]/<service_name> (c) Yakov Fain 2013

RMI Players (c) Yakov Fain 2013

Developing and Running an app using RMI Declare a remote Java interface Implement the remote interface in a Java class Computer A: Start the registry and register the RMI server with it Computer B: Start the server Computer C: Start a Java client that will look up the service in the registry A to get stubs from the server B and calls remote methods. (c) Yakov Fain 2013

Walkthrough 3 1. Download and import the project Lesson25 and review the code with the instructor. 2. Add the following statement at the line 12 of StartServer.java: LocateRegistry.createRegistry(1099);! 3. Add the import statement for LocateRegistry! 4. Run StartServer and it should give a prompt <QuoteService> server is ready 5.Run configura^on for Client.java to specify one program argument: AAPL 6. Run the Client and you should get the random price quote like The price of AAPL is: $1.3335365174267477 (c) Yakov Fain 2013

Homework 1. Study the materials from Lesson 18 and lesson 25 from the textbook.

Addi^onal Reading/Watching Read about working with Yahoo stock quote data feed hjp://www.gummy- stuff.org/yahoo- data.htm. RMI: hjp://docs.oracle.com/javase/tutorial/rmi/ Watch the video on code refactoring and tes^ng: hjp://www.java- tv.com/2013/10/23/tes^ng- and- refactoring- legacy- code- 2/ Watch the video about automated tes^ng: hjp://www.infoq.com/presenta^ons/tes^ng- Java. Create a project that uses unit tests with JUnit.