1 / 7

L22 (Chapter 25) Networking 1

L22 (Chapter 25) Networking 1. Objectives. To comprehend socket-based communication in Java (§25.2). To understand client/server computing (§25.2). To implement Java networking programs using stream sockets (§25.2). To obtain Internet address using the InetAddress class (§25.3).

manng
Download Presentation

L22 (Chapter 25) Networking 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. L22 (Chapter 25) Networking 1

  2. Objectives • To comprehend socket-based communication in Java (§25.2). • To understand client/server computing (§25.2). • To implement Java networking programs using stream sockets (§25.2). • To obtain Internet address using the InetAddress class (§25.3). • To develop servers for multiple clients (§25.4). • To develop applets that communicate with the server (§25.5). • To send and receive objects on the network (§25.6). • To create applications or applets to retrieve files from the network (§25.7). • To render HTML files using the JEditorPane class (§25.8). • To implement Java networking programs using datagram sockets (§25.10 Optional).

  3. After the server accepts the connection, communication between server and client is conducted the same as for I/O streams. The server must be running when a client starts. The server waits for a connection request from a client. To establish a server, you need to create a server socket and attach it to a port, which is where the server listens for connections. After a server socket is created, the server can use this statement to listen for connections. The client issues this statement to request a connection to a server. Client/Server Communications

  4. Data Transmission through Sockets InputStream input = socket.getInputStream(); OutputStream output = socket.getOutputStream();

  5. A Client/Server Example • Problem: Write a client to send data to a server. The server receives the data, uses it to produce a result, and then sends the result back to the client. The client displays the result on the console. In this example, the data sent from the client is the radius of a circle, and the result produced bythe server is the area of the circle.

  6. A Client/Server Example, cont.

  7. A Client/Server Example, cont. Client Code Server Code Start Client Start Server Note: Start the server, then the client.

More Related