ObjectInputStream 与 ObjectOutputStream

      用Socket通信的时候如果要用到ObjectInputStream 与 ObjectOutputStream的话,要确保Server端与Client端ObjectInputStream 与 ObjectOutputStream生成的顺序。

      在Server(Client)端生成一个ObjectInputStream流时必须确保在Client(Server)端生成一个ObjectOutputStream流。

      根据上述原则,合法的可能生成顺序有

      1、

            Server                          Client

            ObjectInputStream      ObjectOutputStream

            ObjectOutputStream    ObjectInputStream

 

      2、

            Server                          Client

            ObjectOutputStream    ObjectInputStream

            ObjectInputStream      ObjectOutputStream

 

     其他情况都会引起阻塞。

 

    引用:

           public ObjectInputStream(InputStream in)
 throws IOException

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.

If a security manager is installed, this constructor will check for the "enableSubclassImplementation" SerializablePermission when invoked directly or indirectly by the constructor of a subclass which overrides the ObjectInputStream.readFields or ObjectInputStream.readUnshared methods.

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值