0

I am writing a client server application, and everything was working fine until now. I didn't change anything but I upgrade the mac OS to maverick, I don't know if its related but I don't see what it could be. When I try to connect to the server, i have a java.net.ConnectException. The client and server run on my computer, and i use a dns address to connect with port 8080. Port 8080 is open in my router's firewall. Here is my server code

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();
}
}

}

When i run the server, I see the msg 'doComms accepted', so i guess its stopping at listener.accept(). (i never see the 'accepted' output.

On the client side, here is the connectoToserver method:

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));}
}       

the socket connection is initiated at the beginning of class, before constructor. The stacktrace is the following:

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)

Thanks a lot to anyone helping me with that, i have no idea what is wrong with it :S

20
  • everything was working fine until now. I didn't change anything - oldest developer excuse in the book. Mar 11, 2014 at 4:59
  • What errors are there on the server? Mar 11, 2014 at 5:02
  • I dont get any error on the server side...the server is just sitting on listener.accept(); Mar 11, 2014 at 5:04
  • try using telnet melucio.no-ip.biz" 8080 Mar 11, 2014 at 5:05
  • telnet: Unable to connect to remote host Mar 11, 2014 at 5:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.