????Socket??????????????????£???????????·???????????????????????У?Socket?????????????????????????????Java?м?????

??????????????????????????????????????????????????????????????????????????????????綽?????????????????У???????????????????綽??С?

java????????

????????????????“????”?????????????????????????java.net????д??????ó???

????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

??????????????????£?

package com.javapp.ch11;
 import java.io.*;
 import java.net.*;
 /**
 * Description: ????“????”????????????????????
 */
 public class EchoClientDemo {
     // ???????????????
     public static final int SERVERPORT = 990;
     public static void main(String[] args) {
         try {
             // ??????????????
             Socket s = new Socket("localhost"??SERVERPORT);
             System.out.println("socket = " + s);
             // ????????????????????
             BufferedReader in = new BufferedReader(new InputStreamReader(s
                     .getInputStream()));
             // ?????????????????μ????????
             PrintWriter out = new PrintWriter(new BufferedWriter(
                     new OutputStreamWriter(s.getOutputStream()))??true);
             // ?????System.in????InputStreamReader???????BufferedReader??
             BufferedReader stdin = new BufferedReader(
                     new InputStreamReader(System.in));
             System.out.println("Enter a string?? Enter BYE to exit! ");
             while (true) {
                 // ?????????????????????????????????????????????????????????
                 out.println(stdin.readLine());
                 // ??????????????У????????????????????
                 String str = in.readLine();
         // ?????????????????????????Enter????????????????????????????????
                 if (str == null) {
                     break;
                 }
                 System.out.println(str);
             }
             s.close();
         } catch (IOException e) {
             System.err.println("IOException" + e.getMessage());
         }
     }
 }