[英]Android socket application running on emulator but not working on device
i am working on a application in which the application has to connect to the java class using socket programming. 我正在开发一个应用程序,其中应用程序必须使用套接字编程连接到java类。 The application is working fine in the android emulator but it is not working on my device. 该应用程序在Android模拟器中运行良好,但它不能在我的设备上运行。 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();
}
好吧,我认为你应该首先检查你的设备和你的服务器 - PC之间的连接,在你的设备上安装Android终端模拟器应用程序并用您的服务器IP地址ping它...然后尝试连接您的设备与服务器...希望你会成功......
因为您的Android使用不使用名称vivekpc的wifi,请尝试将vivekpc更改为您设备的wifi名称。
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: 您正在尝试在PC上连接localhost:
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. 如果您的PC和设备之间没有连接,那么它很自然会落入UnknownHostException部分而无法在您的设备上运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.