简体   繁体   English

Android中的WiFi网络编程

[英]WiFi network programming in android

i want to program a server/client app in android. 我想在android中编写服务器/客户端应用程序。 i have one server class on my pc and client on my android phone. 我的PC上有一个服务器类,而Android手机上有一个客户端。 all permissions are ok. 所有权限都可以。 Here is client: 这是客户:

        try {
        mysocket = new Socket("My PC IP Address", 4444);
    } catch (UnknownHostException e) {...
    } catch (IOException e) {...
    }

here is server: 这是服务器:

        try {
        myServerSocket = new ServerSocket(4444);
    } catch (IOException e) {...
    }

    Socket clientSocket = null;
    try {
        clientSocket = serverSocket.accept();
        System.out.println("Connection Established.");
    } catch (IOException e) {
    }

I uses "Connectify" program on my pc to have an (virtual)access point such that my phone connect to that. 我在个人计算机上使用“ Connectify”程序来拥有一个(虚拟)接入点,以便手机可以连接到该接入点。 But when I try to connect to server in my android app, it hangs and then throws Timed-out exception. 但是,当我尝试连接到我的Android应用中的服务器时,它会挂起,然后抛出Timed-out异常。

This code doesn't look bad. 这段代码看起来还不错。

Are you certain Connectify is working well? 您确定Connectify运作良好吗? You shoud try running both the server and the client you have built on your PC, using two different processes (as an example the server as a standalone and the client in the Android Emulator). 您应该尝试使用两个不同的进程(例如,服务器作为独立服务器和Android Emulator中的客户端)运行在PC上构建的服务器和客户端。

If it works properly from localhost to localhost:4444, the the connection is the cause of the problem, not your code. 如果它可以从localhost正常运行到localhost:4444,则说明连接是问题的原因,而不是您的代码。 And otherwise, you will easily find the bug in your code. 否则,您将很容易在代码中找到该错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在android中获取当前wifi网络的wifi安全类型 - How to obtain wifi security type of current wifi network in android 如何在wifi网络中测量延迟Java Java Android - How to measure latency in a wifi network java android 如何在Android(JAVA)的WiFi网络中发现主机 - How to discover host in a WiFi network in Android (JAVA) Android网络未添加到Wifi列表中 - Android network is not being added to Wifi List Android 8+ - 如何在 android 中以编程方式连接到 wifi 网络? - Android 8+ -How to connect to wifi network programmatically in android? 如何将套接字绑定到Android上的本地wifi网络地址? - How to bind a socket to local wifi network address on Android? 我可以识别与wifi网络连接的所有android的主机名吗? - can I identify host name of all android connected with a wifi network? 如何使android应用进行通信(当它们在同一个wifi网络上时) - how to make to android apps communicate (when they are on the same wifi network) 如何在Android中以编程方式在网络上查找其他WiFi设备的IP地址 - How to find IP address of OTHER WiFi Devices on network programmatically in android 以编程方式将设备连接到android中的同一wifi网络? - Get Devices connected to same wifi network in android programmatically?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM