Java Reference
In-Depth Information
public class PersonnelClient
{
private static InetAddress host;
private static fi nal int PORT = 1234;
public static void main(String[] args)
throws ClassNotFoundException
{
try
{
host = InetAddress.getLocalHost();
}
catch(UnknownHostException uhEx)
{
System.out.println("Host ID not found!");
System.exit(1);
}
talkToServer();
}
private static void talkToServer()
throws ClassNotFoundException
{
try
{
Socket socket = new Socket(host,PORT);
ObjectInputStream inStream =
new ObjectInputStream(
socket.getInputStream());
PrintWriter outStream =
new PrintWriter(
socket.getOutputStream(),true);
//Set up stream for keyboard entry…
Scanner userEntry = new Scanner(System.in);
outStream.println("SEND PERSONNEL DETAILS");
ArrayList<Personnel> response =
(ArrayList<Personnel>)inStream.readObject();
/*
As in ArrayListSerialise, the compiler will
issue a warning for the line above.
Simply ignore this warning.
*/
System.out.println(
"\n* Closing connection… *");
socket.close();
Search WWH ::




Custom Search