1. make sure your mechine is connected to internet.
2. make sure 10.65.111.101 is running by typing "ping 10.65.111.101".

解决方案 »

  1.   

    我的计算机肯定是连接INTERNET。但是不能ping 10.65.111.101。
    请问我该怎么操作?
      

  2.   

    echoSocket = new Socket("10.65.111.101", 7);改成:
    InetAddress ia = InetAddress.getLocalHost();
    echoSocket = new Socket(ia,7);
      

  3.   

    没有问题,我刚试过一遍,除了你用的DataOutputStream.readLine()方法不推荐使用(用了也没有关系).
      

  4.   

    原因很多,可能是防火墙,或是ip地址的问题,或指定的端口号没有打开,所以连接不到指定的ip地址,指定的端口号,你可以将ip改为随便一个存在的ip,存在的端口号,比如www.sohu.com 80就不会出错了。
      

  5.   

    我可以用
    echoSocket = new Socket(127.0.0.1, 7);吗?
    但是我用了没有成功。真想知道风雨朋友是怎么成功的?
      

  6.   

    echoSocket = new Socket(127.0.0.1, 7);吗?可以用:echoSocket = new Socket("127.0.0.1", 7);
    其他都不用改动.
      

  7.   

    对你的程序,如果你是要测试socket的功能,当然只能用它,如果是测试一般的java功能,那什么样的程序都行,对吗?
      

  8.   

    10.65.111.101是一个ip地址
    你换成127。0。0。1或者localhost但是本地没有server还是不行
    在本地写个简单的服务程序先运行就ok了
      

  9.   

    我写了个服务器程序//CommServer.java
    import java.net.*;
    import java.io.*;
    public class commserver
    {
        public static void main(String[] args) throws IOException 
    {        ServerSocket serverSocket = null;     
            try 
    {
                serverSocket = new ServerSocket(1800);        
            }
    catch (IOException e)
    {
                System.err.println("Could not listen on port.");
            
                System.exit(1);
            }
      Socket acceptsocket=null;
         try
    {     acceptsocket = serverSocket.accept();
     }
       catch (IOException e)
    {
         System.err.println("Accept failed.");
       System.exit(1);
    }
            acceptsocket.close();
            serverSocket.close();
        }
    }
    我用javac commserver.java 系统没有出错
    运行java    commserver   在DOS下只是光标闪烁,看不到结果。
    我该怎么办呢
      

  10.   

    第2个程序当然是没有结果了啊,你一连上,就断掉了阿,而且就退出了啊。你在服务器这边,写数据或,读数据,在输出不就有结果了嘛。我用socket差不多有1年多了啊。而且,你的new socket()应该用Socket(String host, int port, InetAddress localAddr, int localPort)这个,我是这么认为的,因为你的port不同啊。
      

  11.   

    我在用File f = new File("C:\javacode\B.java");运行JAVAC 系统提示这条语句通不过。请问这时怎么原因呢?
      

  12.   

    1:如果我在本机
       echoSocket = new Socket("127.0.0.1", 端口号);
      这个端口号该怎么设置?
    2:请问那个第2个程序该怎么修改才能看到结果?请给个例子吧。好吗
    谢谢。
      

  13.   

    我在用File f = new File("C:\javacode\B.java");运行JAVAC 系统提示这条语句通不过。请问这时怎么原因呢?
    ===>Have you use "import java.io.*;"如果我在本机
       echoSocket = new Socket("127.0.0.1", 端口号);
      这个端口号该怎么设置?
    ===>open a dos window and type "netstat -an" to get available ports.
      

  14.   

    我写了个服务器程序//CommServer.java
    import java.net.*;
    import java.io.*;
    public class commserver
    {
        public static void main(String[] args) throws IOException 
    {        ServerSocket serverSocket = null;     
            try 
    {
                serverSocket = new ServerSocket(1800);        
            }
    catch (IOException e)
    {
                System.err.println("Could not listen on port.");
            
                System.exit(1);
            }
      Socket acceptsocket=null;
         try
    {     acceptsocket = serverSocket.accept();
     }
       catch (IOException e)
    {
         System.err.println("Accept failed.");
       System.exit(1);
    }
            acceptsocket.close();
            serverSocket.close();
        }
    }
    我用javac commserver.java 系统没有出错
    运行java    commserver   在DOS下只是光标闪烁,看不到结果。
    我该怎么办呢
      

  15.   

    socket程序是点对点的通信,只开一边当然能不了。邮局卖邮票的窗口没开,你怎么能买到邮票呢!
    我写了一个多线程程序,通过socket传输zip文件,给你做个参考:
    服务器端程序:
    import java.io.*;
    import java.net.*;
    import java.io.BufferedInputStream;public class SocketServer {
    ServerSocket ss=null;
    Socket s=null;
    DataInputStream inStream=null;
    DataOutputStream outStream=null;
    FileInputStream fin = null;public SocketServer() {
      try{
        ss=new ServerSocket(765);
        s.setSoTimeout(3000);
      }catch(Exception e){
        System.out.println(e.toString());
      }
    }void waitForClient(){
      try{
      while(true){
      s=ss.accept();
      ThreadServer thread = new ThreadServer(s);
      thread.start();
      }
      }catch(Exception e){
        System.out.println(e.toString());
      }
    }public static void main(String[] args) {
    SocketServer socketServer1 = new SocketServer();
    socketServer1.waitForClient();
    }
    }线程类:import java.io.*;
    import java.net.*;class ThreadServer extends Thread{  private Socket socket;
      private DataInputStream inStream=null;
      private DataOutputStream outStream=null;
      private FileInputStream fin = null;  public ThreadServer(Socket sock){
        this.socket = sock;
      }  public void run(){
      boolean bool = false;
      //while(!bool){
      try{
      inStream=new DataInputStream(socket.getInputStream());
      outStream=new DataOutputStream(socket.getOutputStream());
      fin = new FileInputStream("C:/temp/socket/200212060001_ds.zip");
      //socket.setSoTimeout(3000);
      byte[] b = new byte[200];
      int i;
      while((i=fin.read(b))!=-1){
      outStream.write(b);
      }
      fin.close();
      socket.close();
      //bool = true;
      }catch(IOException ex){
      System.out.println(ex);
      }
      //}
      }}客户端:
    import java.net.*;
    import java.io.*;public class SocketClient{
    Socket s=null;
    DataInputStream inStream=null;
    DataOutputStream outStream=null;
    FileOutputStream fout = null;public SocketClient() {
    try{
    s=new Socket("192.9.207.52",765); //把这里的IP改成你运行SocketServer.class的IP
    inStream=new DataInputStream(s.getInputStream());
    outStream=new DataOutputStream(s.getOutputStream());
    fout = new FileOutputStream("C:/temp/socket/test11.zip");
    s.setSoTimeout(3000);
    waitData();
    }
    catch(Exception e){
    System.out.println(e.toString());
    }
    }void init() throws Exception{}void waitData(){
    try{
      byte[] b = new byte[200];  
      int i;
      while((i=inStream.read(b))!=-1){
        fout.write(b);
      }
      fout.flush();
      fout.close();
      s.close();
    }catch(Exception e){
    System.out.println(e.toString());
    }
    }    public static void main(String[] args) {
    SocketClient socketClient1 = new SocketClient();
    }
    }在win2k jdk1.3下本机调试通过,希望能帮到你。
      

  16.   

    奇怪,我每次运行java socket程序时,比如服务器端的SOCKET程序编译通过了,可就是在 
    用java  服务器程序
     运行它时,老是一个光标在那不停的闪,无任何结果。
    是什么原因??????
    我运行好几个java socket程序都是这样。
    我的系统是WIN98,用JDK1.4。我好伤心啊!!到底该怎么做??????