Java套接字:程序停在socket.getInputStream()没有错误? [英] Java sockets: Program stops at socket.getInputStream() w/o error?

查看:1245
本文介绍了Java套接字:程序停在socket.getInputStream()没有错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

InetAddress host = InetAddress.getLocalHost();
Socket link = new Socket(host, Integer.parseInt(args[0]));
System.out.println("before input stream");
ObjectInputStream in = new ObjectInputStream(link.getInputStream());
System.out.println("before output stream");
ObjectInputStream out = new ObjectOutputStream(link.getOutputStream());

输入流之前是cmd-line上的最后一个生命值。没有抛出异常。为什么会这样?我不明白...

"before input stream" is the last lifesign on cmd-line. There is no Exception thrown. Why is this happening? I don't understand...

args [0]是5000.
//编辑:flush没有帮助。

args[0] is 5000. //edit: flush doesn't help.

推荐答案

这是因为 ObjectInputStream(InputStream in) -constructor是一个阻塞调用,如果inputStream为空。

This is because the ObjectInputStream(InputStream in)-constructor is a blocking-call if the inputStream is empty.

引用


创建一个读取的ObjectInputStream来自指定的InputStream。从流中读取序列化流头并进行验证。此构造函数将阻止,直到相应的ObjectOutputStream已写入并刷新标头。

Creates an ObjectInputStream that reads from the specified InputStream. A serialization stream header is read from the stream and verified. This constructor will block until the corresponding ObjectOutputStream has written and flushed the header.

这篇关于Java套接字:程序停在socket.getInputStream()没有错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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