如何写一个Android的SocketServer对无线监听 [英] How to write an Android SocketServer to listen on wifi

查看:222
本文介绍了如何写一个Android的SocketServer对无线监听的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 java.net.SocketServer 到一个特定的端口上侦听写了一个线程。它工作正常,在Android模拟器(使用端口转发)。我打算通过WiFi连接到这个端口,当应用程序被使用。但是,的SocketServer 文件说,如果你不提供一个的InetAddress ,在服务器上的本地主机监听。

I've written a thread using java.net.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连接?我怎样才能获得的InetAddress WiFi连接来传递给的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。这是给你,如果你想提名自己的<一href="http://developer.android.com/reference/java/net/ServerSocket.html#ServerSocket%28int,%20int,%20java.net.InetAddress%29"相对=nofollow>本地主机地址。

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.

阅读这两篇文章:

  • Implement a simple Socket Server in Eclipse
  • Simple communication using java.net.Socket

记得有一个无线网络锁和相应的权限。

Remember to have a WiFi lock and the appropriate permissions.

这篇关于如何写一个Android的SocketServer对无线监听的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆