java - 无法打开输出流

标签 java android stream serversocket

由于某些原因,我必须在 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/

相关文章:

java - Install4j:Unix启动器脚本片段使用安装程序变量

java - Android 布局预览器在添加自定义 LinearLayout 时抛出错误

android - 如何保护我的屏幕不被捕获?

android - 在运行计时器时延迟时间

android - Marshmallow windowLightStatusBar = true 在 MI 手机中不工作

java - 路由器后面的android套接字编程

java - "Lambda can be replaced with method reference"in Lazy Logging with Log4J2

scala - Akka流:状态不断

design-patterns - 如何在社交网络中实现事件流

c++ - 输出操纵器 std::ends 是否将 Null 字符添加到输出缓冲区?