Java ObjectInputStream挂起 [英] Java ObjectInputStream hanging

查看:197
本文介绍了Java ObjectInputStream挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在感觉真的很蠢....我基本上是在本地机器上通过TCP连接...当我尝试在客户端制作输入/输出流时,它不会被传递创建对象输入流。是什么赋予了?打印后停止2 ...没有例外或任何事情......这不是我第一次使用这个课程,这也是我迷惑的原因。

I am feeling really stupid right now guys.... basically I am connecting over TCP on a local machine... and when I try to make the In/out streams at the client it wont get passed creating the object input stream. What gives? This stops after printing 2... no exceptions or anything... This isn't the first time I've used this class which is partialy why I am puzzled.

try {
            System.out.println("1");
            mySocket = new Socket("localhost", 11311);
            System.out.println("12");
            oos = new ObjectOutputStream(mySocket.getOutputStream());
            System.out.println("2");
            ois = new ObjectInputStream(mySocket.getInputStream());
            System.out.println("13");

        } catch (Exception e) {
            e.printStackTrace();
        }


推荐答案

来自规范


此构造函数将阻塞,直到相应的ObjectOutputStream
已写入并刷新标题。

This constructor will block until the corresponding ObjectOutputStream has written and flushed the header.

这篇关于Java ObjectInputStream挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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