安卓:ObjectInputSteam.readFully()卡 [英] Android: ObjectInputSteam.readFully() gets Stuck

查看:424
本文介绍了安卓:ObjectInputSteam.readFully()卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

状况:我从客户端向服务器发送通过的ObjectOutputStream 布尔变量。此后,我立即通过 writeChars()函数发送一个字符串数据。服务器通过 readBoolean接收布尔()并相应地产生一个线程。它使用读取字符串的readFully(字节[])

Situation : I send a boolean variable via ObjectOutputStream from a client to a server. Thereafter, I immediately send a string data via writeChars() function. The server receives the boolean via readBoolean() and spawns a thread accordingly. It reads the string using readFully(bytes[]).

问题:服务器挂在行 ObjectInputStream.readFully(字节[])

我是不是应该增加的字节大小,或者是整个的方法错了?

Should I just increase the byte size, or is the whole approach wrong ?

推荐答案

如果这是一个字符串键,您使用的ObjectOutputStream 你应该叫 writeUTF()来写和的readUTF()读它。这个方法实际上第一字节写入到流,然后字节数。在接收端,它读取的字节数,然后知道多少字节期望

If this is a String and you are using ObjectOutputStream you should just call writeUTF() to write it and readUTF() to read it. This method actually first writes the number of bytes to the stream and then the bytes. On the receiving end, it reads the number of bytes and then knows how many bytes to expect.

这篇关于安卓:ObjectInputSteam.readFully()卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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