0

在我的 Android 手机上,我检查了我的 IP 地址是 10.0.0.8 所以,我为我的手机分配了一个套接字

   Socket socket = new Socket("10.0.0.8",3200);

我的服务器 IP 是 10.0.0.6

所以我尝试替代方案,

    Socket socket = new Socket("10.0.0.6",3200);

同样的错误,连接被拒绝。

但是当我进入线路时,它说连接拒绝。我的意思是,为什么连接被拒绝?它本身,无需建立联系。我所做的只是制作一个套接字,但还没有连接。

在我的计算机上,我 ping 10.0.0.6 和 10.0.0.8 并成功。点对点网络已启用。

4

1 回答 1

1

When you run this code, it attempts to connect to the server on a port which may or may not be accepting incoming connections.

This can be seen from the android development references:

Socket(InetAddress dstAddress, int dstPort) Creates a new streaming socket connected to the target host specified by the parameters dstAddress and dstPort. -http://developer.android.com/reference/java/net/Socket.html

For examples of how to use Sockets in your Android program, I suggest looking at this site: http://thinkandroid.wordpress.com/2010/03/27/incorporating-socket-programming-into-your-applications/

于 2013-11-14T19:19:12.360 回答