我的server端和client端分处于不同的网段,网关是不同的,但能够ping通的

解决方案 »

  1.   

    think in java 中的一个CLIENT代码,
    做了少量的修改,最好能找书具体学下:
    //: JabberClient.java
    // Very simple client that just sends
    // lines to the server and reads lines
    // that the server sends.
    import java.net.*;
    import java.io.*;public class JabberClient {
      public static void main(String[] args) 
          throws IOException {
    // 修改到想要的端口号
    String port = "8080";    // Passing null to getByName() produces the
        // special "Local Loopback" IP address, for
        // testing on one machine w/o a network:
        InetAddress addr = 
          InetAddress.getByName(null);
        // Alternatively, you can use 
        // the address or name:
        // InetAddress addr = 
        //    InetAddress.getByName("127.0.0.1");
        // InetAddress addr = 
        //    InetAddress.getByName("localhost");
        System.out.println("addr = " + addr);
        Socket socket = 
          new Socket(addr, port);
        // Guard everything in a try-finally to make
        // sure that the socket is closed:
        try {
          System.out.println("socket = " + socket);
          BufferedReader in =
            new BufferedReader(
              new InputStreamReader(
                socket.getInputStream()));
          // Output is automatically flushed
          // by PrintWriter:
          PrintWriter out =
            new PrintWriter(
              new BufferedWriter(
                new OutputStreamWriter(
                  socket.getOutputStream())),true);
          for(int i = 0; i < 10; i ++) {
            out.println("howdy " + i);
            String str = in.readLine();
            System.out.println(str);
          }
          out.println("END");
        } finally {
          System.out.println("closing...");
          socket.close();
        }
      }
    } ///:~注:我没有调试这个代码,直接考过来的,做简单修改的。
      

  2.   

    以后这种问题,贴出相关代码。
    你用程序开2个Port在你所需要的PC上,做个测试。