Java Reference
In-Depth Information
System.exit(1);
} catch (IOException e) {
System.out.println(e);
System.exit(1);
}
}
public static void testConnection() {
String serverResponse = null;
if (socket != null && in != null && out != null) {
System.out.println("Successfully connected,
now testing...");
try {
// Send data to server
out.println("Here is a test.");
// Receive data from server
while((serverResponse = in.readLine()) !=
null)
System.out.println(serverResponse);
} catch (IOException e) {
System.out.println(e);
System.exit(1);
}
}
}
}
If you're testing this client against a server that successfully accepts the request,
you will see the following result:
Successfully connected, now testing...
Note This program will do nothing on its own. To create a server-side socket applic-
ation that will accept this connection for a complete test, see Recipe 21-1. If you attempt
to run this class without specifying a server host that is listening on the provided port,
Search WWH ::




Custom Search