java - Error 'null' in sockets connection , Android -
this question has answer here:
what trying do:
trying build test app, now, establishing connection between app on android phone (4.2.2)(as client) , java application running on pc (windows 8)(as server) via sockets connection.
what i've done already:
i've made programs both client , server in java on pc , tested them positively (connection got established).
the network:
both phone , pc connected wifi @ home.ipconfig on pc shows address 192.168.56.1 while on logging router shows address of pc 192.168.0.108 (probably don't understand networking :p).
the code:
client(android)
public void connectpc(view view) { try { clientsocket = new socket("192.168.0.108",1025); outstream = clientsocket.getoutputstream(); instream = clientsocket.getinputstream(); data_out = new dataoutputstream(outstream); data_in = new datainputstream(instream); statusview.settext("connected!"); } catch (exception e) { statusview.settext("error: "+e.getmessage()); } }
the server:
import java.net.*; import java.io.*; public class serverside extends thread { serversocket serversocket; public serverside(int port) throws ioexception { serversocket = new serversocket(1025); serversocket.setsotimeout(10000); } public void run() { while(true) { system.out.println("waiting client on port : "+ serversocket.getlocalport()); socket server; try { server = serversocket.accept(); system.out.println("connected : " +server.getremotesocketaddress()); } catch (ioexception e) { // todo auto-generated catch block system.out.println(e.getmessage()); } } } public static void main(string... args) { int port=6066; try { thread t = new serverside(port); t.start(); } catch(ioexception e) { system.out.println(e.getmessage()); } } }
the problem:- connection doesn't establish, catch block shows e.getmessage() null.
ps i've tried 192.168.56.1 ip address too. , added uses permission in manifest file
any in regard please..!
you need print stacktrace rather exception message. give more information debug problem ... including name of exception, , place thrown.
also, bad idea catch exception
, attempt recover it. catching exception
catch sorts of exceptions never expecting. recovering exceptions weren't expecting risky ... because cannot sure safe thing do. typically better let application die ...
Comments
Post a Comment