在outputStream/InputStream中,我如何区分这些字节用于名称,电子邮件,哪些字节用于图片?
我正在创建一个Android应用程序,我想使用outputStream发送图像并使用InputStream接收图像。我想通过outputStream/InputStream从phone1--->phone2发送(姓名,电子邮件,联系人,图片)我如何区分这些字节用于姓名,电子邮件,哪些字节用于图片?
I am creating an Android app and i would like to send image using outputStream and receive using InputStream .I want to send ( name , email , contact , picture ) from phone1--->phone2 through outputStream/InputStream how i differentiate that these bytes are for name , email , what bytes are for picture ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需创建一个自定义二进制协议,例如这样:
byte nameLength,
字节[]名称,
字节电子邮件长度,
字节[]电子邮件,
联系方式 联系方式,
字节[]图片
Just create a custom binary protocol, for example like this:
byte nameLength,
byte[] name,
byte emailLength,
byte[] email,
contact contact,
byte[] picture
要处理这样的事情,您可以使用特定协议发送它...例如您可以发送:
[电话号码],但您可以发送:
[标识符]--[数据],然后当您收到它时,读取标识符并将其从有效负载中剥离,然后根据需要进行处理。
To handle something like this, you could send it with a particular protocol... for instance you could send:
[Phone number] but instead of this you'd have:
[identifier]--[data] then when you receive it, read the identifier and strip it from the payload and then handle it as you need to.