Communication Across Internet
 
 
 
  Java Applet Limitations: Java Applet Possibilities:

  Package = java.net
 
java.net Classes and important methods
 
URL This is a class that represents a URL.  Can create an URLConnection object with its openConnection() method.
URLConnection This class represents a connection with a URL.  Can use this to get an Inputer stream (getInputStream() method) to read/write information.
Socket Abstraction of standard TCP socket.  Provides a client-side socket interface similar to a standard UNIX socket.  This provides Internet connectivity beyond URL and URLConnection classes.
  • Socket(hostName, portNum)
    • must know hostname and portnumber you want to make a connection with.  Portnumbers often indicate the kind of protocol communications you will be performing, e.g. ftp versus telnet.
  • Open a connnection on this socket using getInputStream() as done in URL/URLConnection example below.
  • Once a socket is open you can use I/O streams like in URL/URLConnection example below.
  • close()
    • make sure you close your socket when you are done with your communications (I/O).
ServerSocket In this case, a server-socket does not open a connection but instead has a method action() that waits and listens on the TCP port for a connection request from a client.  
  • In this way, you can create dual-applications: one a client Socket that asks for a connection and the other a ServerSocket that will accept making a connection with it.
getInputStream() This is a method of the URLConnection class.  Will retrieve an InputStream to data I/O with the corresponding Internet/URL file.
 
 
 
 

The Steps:

1) Create a URL object representing file

2)  Create an URLConnection object that can load this URL and make a connection to the site hosting it.

3)  Using getInputStream() method of the URLConnection object, create an InputStreamReader that can read  from this URL.

4)  If you wish create a different kind of reader, e.g. BufferedReader, as we did before with File I/O to more efficiently read the data as you wish.
 
 

 
 
 
 
 Example_Application   Example_Applet