SOCKET客户端:
try{
Socket netspace = new Socket("www.netspace.org", 7);
BufferedReader input = new BufferedReader(new InputStreamReader(netspace.getInputStream()));
PrintWriter output = new PrintWriter(netspace.getOutputStream(), true);
}catch(UnknownHostException expt){
System.err.println("Unknown host:" + except);
System.exit(1);
}catch(IOException excpt){
System.err.println("Failed I/O:" + excpt);
System.exit(1);
}
output.println("test");
String testResponse = input.readLine();
SOCKET服务器端
try{
ServerSocket server = new ServerSocket(2222);
Socket clientConn = server.accept();
BufferedReader input = new BufferedReader(new InputStreamReader(clientConn.getInputStream()));
PrintWriter output = new PrintWriter(clientConn.getOutputStream(), true);
}catch(IOException excpt){
System.err.println("Failed I/O:" + excpt);
System.exit(1);
}