Java Reference
In-Depth Information
Figure 17.11 The URLConnectionDemo program shows the contents of an HTML page.
This figure shows part of the output of the URL http://www.javalicense.com.
Lab 17.1: Using Sockets
The purpose of this lab is to become familiar with working with sockets.
You will write a client/server network program that allows a simple con-
versation to take place between two computers.
1. Write a program named TalkServer that uses a ServerSocket object
to listen for clients on port 5050.
2. When a client connects, have the TalkServer program read in a
String from the client using the readUTF() method of the DataInput-
Stream class. You will need to create a new DataInputStream by
using the input stream of the socket. Print out the String that is read.
3. The TalkServer program should then send a String to the client
using the writeUTF() method of the DataOutputStream class, send-
ing the String to the client's socket. The string sent to the client
should be input from the console input using the keyboard.
4. This process should continue until the connection is lost somehow.
In other words, the TalkServer reads in a String, displays it, and
then inputs a String from the keyboard and sends it to the client.
5. Write a program named TalkClient that uses the Socket class to con-
nect to the server socket of the TalkServer program.
6. The client should send a String input from the keyboard to the
server using the writeUTF() method. Then, the TalkClient should
read in a String from the Server using the readUTF() method, dis-
playing the String.
Search WWH ::




Custom Search