ConnectException Java

时间:2014-03-11 04:55:28

标签: java android apache servlets

我正在编写客户端服务器应用程序,到目前为止一切正常。我没有改变任何东西,但我将mac OS升级为特立独行,我不知道它是否相关,但我不知道它可能是什么。当我尝试连接到服务器时,我有一个java.net.ConnectException。客户端和服务器在我的计算机上运行,​​我使用dns地址连接端口8080.端口8080在我的路由器的防火墙中打开。 这是我的服务器代码

public class Server {

private static int port=8080, maxConnections=0;

public static void main(String[] args) {
int i=0;

try{
  ServerSocket listener = new ServerSocket(port);
  System.out.println("listerner created");
  Socket server;
  System.out.println("socket created");

    while(true){
    doComms connection;
    System.out.println("doCommscreated");
    server = listener.accept();
    System.out.println("accepted");
    doComms conn_c= new doComms(server);
    Thread t = new Thread(conn_c);
    t.start();
  }
} catch (IOException ioe) {
  System.out.println("IOException on socket listen: " + ioe);
  ioe.printStackTrace();
}
}

}

当我运行服务器时,我看到msg'doComms接受',所以我猜它停在listener.accept()。 (我从未看到'接受'的输出。

在客户端,这是connectoToserver方法:

private void connectToServer() throws IOException{
    try{
        Log.w("myApp1", "no network");
    connection = new Socket("melucio.no-ip.biz",8080);
    }catch(IOException e){Log.e("myapp", "STACKTRACE");
    Log.e("myapp", Log.getStackTraceString(e));}
}       

套接字连接是在类的开头,构造函数之前启动的。 堆栈跟踪如下:

03-11 00:14:57.474: E/myapp(275): STACKTRACE
03-11 00:14:57.474: E/myapp(275): java.net.ConnectException: melucio.no-   ip.biz/24.201.246.8:8080 - Connection refused
03-11 00:14:57.474: E/myapp(275):   at    org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:254)
03-11 00:14:57.474: E/myapp(275):   at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:219)
03-11 00:14:57.474: E/myapp(275):   at java.net.Socket.startupSocket(Socket.java:781)
03-11 00:14:57.474: E/myapp(275):   at java.net.Socket.tryAllAddresses(Socket.java:194)
03-11 00:14:57.474: E/myapp(275):   at java.net.Socket.<init>(Socket.java:258)
03-11 00:14:57.474: E/myapp(275):   at java.net.Socket.<init>(Socket.java:222)
03-11 00:14:57.474: E/myapp(275):   at com.example.client.Sin.connectToServer(Sin.java:109)
03-11 00:14:57.474: E/myapp(275):   at com.example.client.Sin.access$0(Sin.java:106)
03-11 00:14:57.474: E/myapp(275):   at com.example.client.Sin$1.run(Sin.java:38)
03-11 00:14:57.474: E/myapp(275):   at com.example.client.Sin$3.run(Sin.java:157)
03-11 00:14:57.474: W/dalvikvm(275): threadid=8: thread exiting with uncaught exception (group=0x4001d800)
03-11 00:14:57.474: E/AndroidRuntime(275): FATAL EXCEPTION: Thread-9
03-11 00:14:57.474: E/AndroidRuntime(275): java.lang.NullPointerException
03-11 00:14:57.474: E/AndroidRuntime(275):  at com.example.client.Sin.sendInfo(Sin.java:118)
03-11 00:14:57.474: E/AndroidRuntime(275):  at com.example.client.Sin.access$1(Sin.java:114)
03-11 00:14:57.474: E/AndroidRuntime(275):  at com.example.client.Sin$1.run(Sin.java:39)
03-11 00:14:57.474: E/AndroidRuntime(275):  at com.example.client.Sin$3.run(Sin.java:157)

非常感谢任何帮助我的人,我不知道它有什么问题:S

0 个答案:

没有答案