1

i'm developing a small example about socket connection between android and ios (via wifi), after trying, the connection hasn't been established. Here is what I have done so far, I created a server on ios (used Bonjour to publish the service). I also created a client on android. However, after starting the server on ios, I also got the log:

ServerSocketConnection[3487:c07] Bonjour Service Published: domain(local.) type(_serversocket._tcp.) name(Macmini) port(54065)

Which means the server starting ok.

To the client part(android), I created the client through Socket class, some few lines of code:

Socket s = new Socket("local.", 54065);
OutputStream out = s.getOutputStream();
PrintWriter output = new PrintWriter(out);
output.println("Hello Android!");
BufferedReader input = new BufferedReader(new InputStreamReader(s.getInputStream()));
String st = input.readLine();

Putting it into AsyncTask to execute. However, I got the UnknowHostException:

08-06 12:45:44.460: W/System.err(873): java.net.UnknownHostException: Unable to resolve host "local.": No address associated with hostname

I'm a newbie to this kind of problem so any ideas what the problem is? I know it's related to the "host" thing but need the way to fix it. *Note: I run 2 apps on 2 simulators (ios and android) as the same wifi network and same MAC, maybe this is the problem? any help would be appreciated and sorry for my English, it's not my native one.

4

1 回答 1

0

使用 iPhone 的实际 IP 地址而不是“本地”。

在 Android 上,您可以通过设置 -> WiFi -> 高级找到手机的 IP。不确定 iPhone 是否提供相同的选项。

附言。还要确保您的清单中有互联网许可;

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
于 2013-08-06T06:12:50.457 回答