简体   繁体   English

Android套接字应用程序在模拟器上运行但不在设备上运行

[英]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.

相关问题 当我的android应用程序在android设备/模拟器上运行时Jsoup无法正常工作 - Jsoup is not working when my android application is running on android device/emulator 我的Android应用程序在模拟器上运行,但无法在我的Android设备上运行 - My Android application runs on emulator but not working on my android device 在Android模拟器上运行应用程序 - running application on android emulator 在仿真器上工作但不在真正的Android设备上 - Working on Emulator but not on the real Android device 在Android模拟器上运行Facebook应用程序 - running facebook application on android emulator 在设备/仿真器中运行时,应用程序崩溃 - Application crashes while running in Device/Emulator 在Android模拟器上运行的客户端无法创建套接字 - Client running on Android emulator cannot create socket 应用程序在模拟器上运行,但无法在真实设备上运行 - App running on emulator but not working on real device Andriod应用程序未在移动模拟器或设备上运行,但可在平板电脑模拟器上运行 - Andriod application not running on mobile emulator or device but works on tablet emulator 后退按钮在模拟器上运行,但在Android设备中不运行 - back button is working on emulator but it is not working in device in android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM