soc=new ServerSocket(6666);
                svrSoc=soc.accept();
 objIn=new ObjectInputStream(svrSoc.getInputStream());
监听6666端口,获取input信息objIn
strMsg=(String)objIn.readObject();
            System.out.println("The client said:"+strMsg);

解决方案 »

  1.   

    同意楼上.建议楼主看看《thinking in java》,那里有详细说明。
      

  2.   

    以下是客户端代码,声明了两个输入流和一个输出流
    Socket comSocket = null;
    DataInputStream in = new DataInputStream(comSocket.getInputStream());
    DataInputStream stdIn = new DataInputStream(System.in);
    PrintStream out = new PrintStream(comSocket.getOutputStream());
    while ((fromServer = in.readLine()) != null)
            {
                System.out.println("Server: " + fromServer);
                //这里的fromServer是输出服务器的的流,为什么?
    }
    以下是服务端代码,声明了一个输入流和一个输出流
    Socket clientSocket = null;
    clientSocket = serverSocket.accept();
    PrintStream out = new PrintStream(
                    new BufferedOutputStream(
                    clientSocket.getOutputStream(), 1024), false);
    DataInputStream in = new DataInputStream(
                    new BufferedInputStream(clientSocket.getInputStream()));
    while ((inputLine = in.readLine()) != null)
    {
           System.out.println(inputLine);
           //这里的inputLine又是客户端从键盘输入的(System.in),为什么?怎么传过来的
    }