Misc. Java Alittle more network programming & Using jar files to share your work.

Slides:



Advertisements
Similar presentations
User Interfaces File I/O and Exceptions (c) IDMS/SQL News
Advertisements

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.
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.
CIS – Spring Instructors: Geoffrey Fox, Bryan Carpenter Computational Science and.
Using Java without BlueJ Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling BlueJ projects A BlueJ.
28-Jun-15 Basic Protocols. 2 Sockets Sockets, or ports, are a very low level software construct that allows computers to talk to one another When you.
Strings and File I/O. Strings Java String objects are immutable Common methods include: –boolean equalsIgnoreCase(String str) –String toLowerCase() –String.
Java Review 2. The Agenda The following topics were highlighted to me as issues: –File IO (Rem) –Wrappers (Rem) –Interfaces (Rem) –Asymptotic Notation.
15-Jul-15 Basic Protocols. 2 Sockets Sockets, or ports, are a very low level software construct that allows computers to talk to one another When you.
Networking java.net package, which provides support for networking. Its creators have called Java “programming for the Internet.” Socket :- A network socket.
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 Programming: I/O1 Java I/O Reference: java.sun.com/docs/books/tutorial/essential/io/
Socket Programming in Java -First Step of Network Programming-
Greg Jernegan Brandon Simmons. The Beginning…  The problem Huge demand for internet enabled applications and programs that communicate over a network.
From BlueJ to NetBeans SWC 2.semester.
TCP/IP protocols Communication over Internet is mostly TCP/IP (Transmission Control Protocol over Internet Protocol) TCP/IP "stack" is software which allows.
Lab 6: Introduction to Sockets (Web Programming – Part 1) Reference: Head First Java (2 nd Edition) by Kathy Sierra & Bert Bates.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Echo Networking COMP
Network Programming and Sockets CPSC 363 Computer Networks Ellen Walker Hiram College (Includes figures from Computer Networking by Kurose & Ross, © Addison.
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
Practicum: - Client-Server Computing in Java Fundamental Data Structures and Algorithms Margaret Reid-Miller 13 April 2004.
Object Oriented Programming in Java Lecture 16. Networking in Java Concepts Technicalities in java.
1 Recitation 8. 2 Outline Goals of this recitation: 1.Learn about loading files 2.Learn about command line arguments 3.Review of Exceptions.
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.
JAVA PROGRAMMING BASICS CHAPTER 2. History of Java Begin with project Green in 1991 founded by Patrick Noughton, Mike Sheridan and James Gosling who worked.
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.
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.
Introduction IS Outline  Goals of the course  Course organization  Java command line  Object-oriented programming  File I/O.
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,
5-Dec-15 Sequential Files and Streams. 2 File Handling. File Concept.
CS 4244: Internet Programming Network Programming in Java 1.0.
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
Java Server Programming Web Interface for Java Programs.
1 CSCD 330 Network Programming Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 9 Client-Server Programming.
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.
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
I/O Basics 26 January Aside from print( ) and println( ), none of the I/O methods have been used significantly. The reason is simple: most real.
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.
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.
Socket Programming in Java -First Step of Network Programming-
3/5/2002e-business and Information Systems1 Java Java Java Virtual Machine (JVM) Java Application Program Interface (API) HW Kernel API Application Programs.
Network Programming: Servers. Agenda l Steps for creating a server Create a ServerSocket object Create a Socket object from ServerSocket Create an input.
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.
Agenda Socket Programming The OSI reference Model The OSI protocol stack Sockets Ports Java classes for sockets Input stream and.
SOCKET PROGRAMMING WITH JAVA By Collin Donaldson.
Network Programming. These days almost all devices.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Echo Networking COMP
Echo Networking COMP
Introduction to programming in java
CSE 341, S. Tanimoto Java networking-
Strings and File I/O.
PRESENTED To: Sir Abid………. PRESENTED BY: Insharah khan………. SUBJECT:
Basic Protocols 24-Nov-18.
Socket programming - Java
Basic Protocols 19-Feb-19.
Servlets Servlets are modules that extend the functionality of a “java-enabled” web-server They normally generate HTML code and web content dynamically.
Servlets Servlets are modules that extend the functionality of a “java-enabled” web-server They normally generate HTML code and web content dynamically.
Chapter 2: Application layer
Programming TCP Sockets
CS18000: Problem Solving and Object-Oriented Programming
Presentation transcript:

Misc. Java Alittle more network programming & Using jar files to share your work

Socket: Java Network Connection Analogous to an electrical socket, the client can plug into the server This creates a connection along which information can flow When the client disconnects, the socket is free for the next client to use Input and output streams can be created to allow communication over the socket. But I want to experiment at home…

You know an IP number

Date Server Example (unchanged) import java.util.Date; import java.net.*; import java.io.*; public class DateServer { static final public int portNumber = 4291; public static void main(String [] args) { try { DateServer world = new DateServer(); } catch (IOException e) { System.out.println("IO exception " + e); } // end try-catch } // end main public DateServer ( ) throws IOException { ServerSocket server = new ServerSocket(portNumber); for (int i = 0; i < 3; i++) { System.out.println("Waiting for a client"); Socket sock = server.accept(); System.out.println("Got client #" + i); OutputStreamWriter out = new OutputStreamWriter(sock.getOutputStream()); String message = "Current date and time is " + new Date() + "\n"; out.write(message); out.close(); } // end for } // end DateServer } // end class DateServer

Date Client Example import java.net.*; import java.io.*; public class DateClient { static final public int portNumber = 4291; public static void main(String [] args) { try { DateClient world = new DateClient(); } catch (IOException e) { System.out.println("Received an IO exception " + e); } // end try-catch } // end main public DateClient ( ) throws IOException { // Socket sock = new Socket(InetAddress.getLocalHost(), portNumber); byte [] ipAddr = {(byte) 134, (byte) 161, (byte) 243, (byte) 240}; Socket sock = new Socket(InetAddress.getByAddress(ipAddr), portNumber); // Socket sock = new Socket(InetAddress.getByName("fienup2.cs.uni.edu"), portNumber); Reader isread = new InputStreamReader(sock.getInputStream()); BufferedReader input = new BufferedReader(isread); System.out.println("message is " + input.readLine()); } // end DateClient } // end class DateClient

Possible Limitations/Problems Your internet service provider might only give you one IP address. That you “share” between machines. The IP address might vary, i.e., assigned dynamically each time you connect.

Making a Double-Clickable.jar File Some of you have written Frogger games of which you are quite proud. You want to share your handiwork with your friends, family, potential employers. How you can you make a double-clickable application from your Java program? Many industry-grade development environments include tools for creating double-clickable apps. But we are not using one. Many of these professional tools are quite complex. Learning them just for the sake of creating a double-clickable app seems crazy. Without making a double-clickable app, your program will be hard or impossible for many others to use. Therefore, use the Java Development Kit's jar tool to create a double- clickable Java archive file. jar packages a bunch of files into a single archive file that you can give to another or offer for download on the web. –If we tell the archive which class file contains the main() method, then users will be able to double-click on the file's icon and run it like a standalone application. –The file that tells the archive this information is called a manifest file. –The manifest acts like a "read me" file for the Java virtual machine can read. When we run jar, it automatically creates a manifest file for the archive. Unfortunately, the default manifest file does not include a definition of the class that contains the main() method.

Making a Double-Clickable.jar File Here are the steps you can use to create a double-clickable jar file. I'll illustrate them by creating the double-clickable cannonworld.jar. Create a manifest file, manifest.mf for your application and place it in the directory with *.class files Manifest-Version: 1.0 Created-By: 1.5.0_06 Main-Class: CannonGameDriver Go to your Unix shell (or perhaps Windows DOS window). Change into the directory containing your *.class files and manifest.mf. Use jar to create your archive. The command you need is: jar cfm jarFileName manifest.mf *.class where jarFileName is what you want to call your archive. To create my archive, I entered: jar cfm cannonworld.jar manifest.mf *.class Move your jar file to whatever location you desire. It's also fun to make your own icon for the double-clickable file. That's another one of those things that industrial-strength IDEs offer do for us. jar does not. You can read more about jar by typing "man jar" at your Unix prompt, or by visiting the JDK documentation.the JDK documentation