客户端套接字无法连接到运行套接字服务器 [英] Client Socket cannot connect to running Socket server

查看:218
本文介绍了客户端套接字无法连接到运行套接字服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Android客户端应用程序与服务器通信,使用插槽

I have Android client app that communicates with server using Socket.

在我的机器,的SocketServer (服务器也用Java编写的)被监听 127.0.1.1 的端口 8666 。我也有在Android应用程序应用程序清单中加入互联网访问权限。

On my development machine, SocketServer (server is also written in Java) is listening at 127.0.1.1 at port 8666. I also have added Internet access permissions in App manifest of Android app.

但是,当我尝试使用客户端=新的Socket(127.0.1.1,8666),以实例化Socket对象,它会抛出 IOException异常拒绝连接消息(也尝试过使用本地主机,而不是手动提供IP地址,但它不科技工作为好)。虽然我可以轻松地从简单的控制台的Java程序连接到服务器。

But when I attempt to instantiate Socket object using client = new Socket("127.0.1.1",8666), it throws IOException with connection refused message (also tried using localhost instead of manually giving IP address, but it doesn't work as well). While I can easily connect to server from simple console Java program.

什么在这里可能是错了吗?

What could be wrong here?

我在某些方面问题涉及到<一个href="http://stackoverflow.com/questions/5224474/how-can-an-android-virtual-device-use-the-local-computers-internet">this.我试图访问相同,其中仿真器正在运行的机器上运行的服务器。

My question in some ways relates to this. I AM attempting to access a server running in the machine same in which emulator is running.

注意:我知道它不推荐任何活动类进行网络的IO,而我没有做这种方式要么,高于code是只是简单理解问题

Note: I know its not recommended to perform network IOs in any Activity class, and I'm not doing that way either, above code is just a problem simplified to understand.

推荐答案

尝试使用,端口转发

这是在亚行的位置命令提示符下,

From command prompt at adb location,

ADB将TCP:8666 TCP:8666

转发命令来设置任意的端口转发 - 对一个模拟器/设备实例的不同端口的特定主机端口上的请求转发。这里是你如何将主机端口8666的转发设置为模拟器/设备端口8666:

The forward command to set up arbitrary port forwarding — forwarding of requests on a specific host port to a different port on an emulator/device instance. Here's how you would set up forwarding of host port 8666 to emulator/device port 8666:

如果这没有帮助,然后发布您的code和logcat的错误。

If this doesn't help then post your code and logcat errors.

这篇关于客户端套接字无法连接到运行套接字服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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