由于某些原因,我必须在 android SocketServer 上设置它等待与计算机的连接。一切顺利,与客户端(计算机)的套接字正在创建,但流未打开。它只是暂停,没有任何错误或消息。
客户:
s = new Socket(ip, 4567);
ois = new ObjectInputStream(s.getInputStream());
System.out.println("ois..");// not showing, so can't open input stream
oos = new ObjectOutputStream(s.getOutputStream());
System.out.println("oos.."); // same here
服务器:
socket = new ServerSocket(4567);
System.out.println("Waiting for connection,,"); // showing
client = socket.accept();
System.out.println("Connected"); //showing
ois = new ObjectInputStream(client.getInputStream());
System.out.println("ois.."); // not showing
oos = new ObjectOutputStream(client.getOutputStream());
System.out.println("oos.."); // not showing too
System.out.println("Stream,s opened");
我的 apk 具有 INTERNET 权限。我使用的是 4567 端口。任何其他应用程序都不会阻止该端口。
可能出了什么问题?
最佳答案
首先尝试在服务器中打开 ObjectOutputStream。
socket = new ServerSocket(4567);
System.out.println("Waiting for connection,,"); // showing
client = socket.accept();
System.out.println("Connected"); //showing
oos = new ObjectOutputStream(client.getOutputStream());
ois = new ObjectInputStream(client.getInputStream());
System.out.println("Stream,s opened");
关于java - 无法打开输出流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10339317/