Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试过谷歌,但甚至看不到关于这个的帖子。当我想在android中创建socket时,我们在PC中创建socket的规则是否适用于android?程序监听一个端口并等待创建套接字?
你有一个ServerSocket和一个Socket。打电话Socket client = ss.accept()等到客户挂机。如果您不确定哪个端口是空闲的,请使用ss = new ServerSocket()。这将自动分配一个空闲端口。还要确保您不在主线程上执行此操作,并在清单中声明相应的权限。
ServerSocket
Socket
Socket client = ss.accept()
ss = new ServerSocket()