import java.io.*;
import java.net.*;
/**
 * Insert the type's description here.
 * Creation date: (00-11-3 18:08:18)
 * @author: Leon Qin 
 */
public class TestServer {
     public static void main(String args[]) {
ServerSocket ssServer=null;
Socket sSocket=null;
InputStream isIn=null;
OutputStream osOut=null; for(;;){
try {
              ssServer=new ServerSocket(1234);
     System.out.println("Waiting for request......\n");
     sSocket=ssServer.accept();
     isIn=sSocket.getInputStream();
     String sSocketIn=(new DataInputStream(isIn)).readUTF();
     System.out.println(sSocketIn);
     osOut=sSocket.getOutputStream();
     (new DataOutputStream(osOut)).writeUTF("I got it!\n");
     System.out.println("Answered!\n");
}
catch(Exception e){}
}
    }
}客户端:
import java.io.*;
import java.net.*;
/**
 * Insert the type's description here.
 * Creation date: (00-11-3 18:08:18)
 * @author: Leon Qin 
 */
public class TestClient {
public static void main(String args[]) {
  Socket sClient = null;
  OutputStream osClient = null;
  InputStream isClient = null;
  InputStreamReader isrUserIn = new InputStreamReader(System.in);
  BufferedReader brUserIn = new BufferedReader(isrUserIn);
  String sUserIn = null;
  for (;;) {
   try {
sUserIn = brUserIn.readLine();
sClient = new Socket("127.0.0.1", 1234);
osClient = sClient.getOutputStream();
(new DataOutputStream(osClient)).writeUTF(sUserIn);
isClient = sClient.getInputStream();
System.out.println((new DataInputStream(isClient).readUTF()));
} catch (Exception e) {
}
}
}
}这样子不知道行不行。