Java Reference
In-Depth Information
private static void startServer()
{
do
{
try
{
socket = serverSocket.accept();
inStream =
new Scanner(socket.getInputStream());
outStream =
new ObjectOutputStream(
socket.getOutputStream());
/*
The above line and associated declaration
are the only really new code featured in
this example.
*/
String message = inStream.nextLine();
if (message.equals(
"SEND PERSONNEL DETAILS"))
{
outStream.writeObject(staffListOut);
outStream.close();
}
System.out.println(
"\n* Closing connection… *");
socket.close();
}
catch(IOException ioEx)
{
ioEx.printStackTrace();
}
}while (true);
}
}
The only new point worthy of note in the code for the client is the necessary
inclusion of throws ClassNotFoundException , both in the method that
directly accesses the ArrayList of Personnel objects (the run method) and in the
method that calls this one (the main method)…
import java.io.*;
import java.net.*;
import java.util.*;
Search WWH ::




Custom Search