从服务器套接字读取和写入消息
import java.io.*; import java.lang.ClassNotFoundException; /** from NowJava.com**/ import java.net.*; public class SocketServer{ private static ServerSocket server; private static int port = 3002; public static void main(String args[]) throws IOException, ClassNotFoundException{ server = new ServerSocket(port); while(true){ System.out.println("Waiting for client request"); Socket socket = server.accept(); BufferedReader ois = new BufferedReader(new InputStreamReader(socket.getInputStream())); /* N o w J a v a . c o m */ String message = ois.readLine(); System.out.println("Message Received: " + message); ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream()); oos.writeObject("Hi Client "+message); ois.close(); oo