Reputation: 1121
i am working on a application in which the application has to connect to the java class using socket programming. The application is working fine in the android emulator but it is not working on my device. There is no socket connectivity between my device and computer when i run it on my device. I am including some of my code for socket connection here please check and suggest me some solutions. its urgent..!!
try {
socket = new Socket(InetAddress.getByName("vivek-PC")
.getHostAddress(), 8888);
dataOutputStream = new DataOutputStream(socket.getOutputStream());
dataInputStream = new DataInputStream(socket.getInputStream());
} catch (UnknownHostException e) {
// textIn.setText("Button Clicked" + e);
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Upvotes: 1
Views: 1635
Reputation: 1241
well i think you should first check the connection between your device and ur server-PC by installing android terminal emulator app on ur device and ping it with your server ip address.....then try to connect your device with server...hope u'll succeed....
Upvotes: 2
Reputation: 740
There is no socket connectivity between my device and computer when i run it on my device.
You are trying to connect localhost on your PC here:
InetAddress.getByName("vivek-PC").getHostAddress()
If there is no connection between your PC and device, it's so natural that it will fall into UnknownHostException part and not work on your device.
Upvotes: 0
Reputation: 1028
Because your android uses wifi which does not use the name vivekpc, try changing vivekpc to the wifi name of your device.
Upvotes: 1