Networking - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Networking

Description:

Networking is the ability for threads of execution to communicate with other ... getByName('localhost'); getLocalHost(); Data Transfer ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 13
Provided by: rob1125
Category:

less

Transcript and Presenter's Notes

Title: Networking


1
Networking
  • Robert Salkin
  • CSI 445 Advanced Java
  • Summer 2006, 6W3

2
What is Networking?
  • Networking is the ability for threads of
    execution to communicate with other threads of
    execution on the same computer or another
    computer using Internet facilities.
  • java.net contains many useful classes for this
    task.

3
Network Participants
  • Client
  • Attempts to connect.
  • Requests information.
  • Server
  • Accepts a connection.
  • Responds to requests.
  • Together, they make a client-server relationship.

4
Communication Types
  • Stream or Socket-based
  • A connection is established between client and
    server.
  • Data is guaranteed to arrive.
  • The connection type most often used.
  • Datagram or Packet-based
  • Connectionless.
  • Packets may be lost, disordered, or duplicated.
  • Not often used, except for streaming data where
    packet loss is preferred over the slow down due
    to the connections overhead.

5
World Wide Web
  • The protocol used on the World Wide Web (WWW) is
    HTTP (Hypertext Transfer Protocol).
  • Resources may be accessed on the WWW via HTTP
    using a URL (Uniform Resource Locator).
  • A URL is a URI (Uniform Resource Identifier) for
    documents.

6
WWW Components
  • A URL object can be used to represent a document
    location.
  • URL url new URL( http//java.sun.com/ )
  • The contents of the page represented by the URL
    can be retrieved and displayed in different ways
  • In a JApplet
  • getAppletContext().showDocument(url)
  • In a JEditorPane
  • ep.setPage(url)
  • Storing the data
  • Object o url.getContent()
  • Assuming it is HTML, cast it to a string.

7
Addresses and Ports
  • An IP (Internet Protocol) address is a unique
    series of numbers used to identify a specific
    computer on the internet.
  • A (software) port is an address internal to a
    computer, used to route incoming data to the
    correct application.

8
Stream Sockets (Server)
  • Create a ServerSocket
  • ServerSocket server new ServerSocket(port)
  • Wait for a connection (and accept it)
  • Socket sock server.accept()

9
Stream Sockets (Client)
  • Open a Socket connection with the server address
    and port
  • Socket conn new Socket( addr, port)
  • Or, create the socket, then open the connection
  • conn.connect(address)

10
Address Conversion
  • The InetAddress class has useful methods to
    specify addresses
  • getByName(localhost)
  • getLocalHost()

11
Data Transfer
  • To send and receive data, use the input and
    output streams
  • conn.getInputStream()
  • conn.getOutputStream()
  • Wrap those streams with
  • ObjectInputStream
  • ObjectOutputStream
  • or
  • Scanner
  • Formatter

12
Remember to Close
  • As with a file (and streams!), close sockets when
    they are no longer needed
  • conn.close()
Write a Comment
User Comments (0)
About PowerShow.com