如何编写一个 Android SocketServer 来监听 wifi

编程入门 行业动态 更新时间:2024-10-27 16:25:36
本文介绍了如何编写一个 Android SocketServer 来监听 wifi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经使用 java.SocketServer 编写了一个线程来侦听特定端口.它在 android 模拟器中运行良好(使用端口转发).我打算在使用应用程序时通过 wifi 连接到这个端口.但是,SocketServer 文档说,如果您不提供 InetAddress,服务器会在 localhost 上侦听.

I've written a thread using java.SocketServer to listen on a particular port. It works fine in the android simulator (using port forwarding). I'm planning to connect over wifi to this port when the app is being used. However, the SocketServer documentation says that if you don't supply an InetAddress, the server listens on localhost.

如果我不提供地址,我将无法通过 wifi 连接,我是否正确?如何将 wifi 连接的 InetAddress 传递给 SocketServer?

Am I correct that if I do not supply the address, I will not be able to get a connection over wifi? How can I get the InetAddress of the wifi connection to pass to the SocketServer?

推荐答案

当您创建 ServerSocket 时,您会监听 localhost 上的 端口.如果你想提名你自己的 本地主机地址.

When you create a ServerSocket you listen to a port on the localhost. It's up to you if you want to nominate your own local host address.

阅读这两篇文章:

  • 在Eclipse中实现一个简单的Socket Server
  • 使用 java.Socket 的简单通信

记得有一个 WiFi 锁和适当的权限.

Remember to have a WiFi lock and the appropriate permissions.

更多推荐

如何编写一个 Android SocketServer 来监听 wifi

本文发布于:2023-11-23 14:24:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1621765.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Android   SocketServer   wifi

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!