Client-Server Program, can conncet from Java client but not from Android -
I have a Java client / server program that is very straightforward and original, but it works fine though, now I have an Android I'm trying to write clients, and I'm unable to connect to the server from my Android client. I'm using almost identical code for the Android networking code as I use for the general customer. My Android code is simple, it all starts this thread with onCreate:
Private Full Serverport = 8889; Private string server IP = "192.168.5.230"; Private socket socket = null; Private threads ClientTrade = New thread ("ClientTread") {@ Override Public Wide Run} {try {socket = new socket}) Socket.connect (New InetSocketAddress (Server IP, Server Port), 1000); DataInputStream din = New DataInputStream (socket.getInputStream ()); DataOutputStream dout = New Data Optical Stream (socket.getOutputStream ()); While (true) {string message = din.readUTF (); SetPicture ("picture1"); }} Hold (unknownhostexception e) {// Todo auto-generated catch block e.printStackTrace (); } Grip (IOException E) {// TODO Auto-Generated Catch Block e.printStackTrace (); }}}; The port is running on my server is the correct port, as is the IP address (which I got from ifconfig because I know you can not use the local host). When I run my normal PC client with a similar port and IP address, the connection goes through, but when I run this code on my Android device, when I try to connect when the socket timeout is over .
Do anyone have any suggestions where I am going wrong? Thanks for the help.
Double-check that you've added the permission permission in the manifest file: < Pre> & lt; Usage-permission Android: name = "android.permission.INTERNET" /> But, more importantly, 1902.68.xx is a local or non-roulette network, so that you have to stay on the same network, or the person whom was 1902.168 .5.230 to reach the address. You say that it does not work on trying on your device - are you running on local WiFi or are you on your mobile network? If you are on mobile, try it with WiFi.
Comments
Post a Comment