通过套接字发送 5MB 数据?
您好,我想使用 Java 编程语言通过 TCP 从服务器向 Android 客户端发送固定数量的数据(例如 5MB)。数据并不重要,它会被丢弃在客户端,我这样做只是为了在手机上进行性能测量。
谁能推荐一种实现此目标的好方法?如何让服务器不断发送大量数据?没有从文件中读取一行,然后发送这些字节的间歇性行为......然后读取另一行并发送这些字节。
有想法吗?干杯。
Hi I want to send a fixed amount of data (say 5MB) from server to Android client over TCP using the Java programming language. The data doesn't matter it will be dropped at the client I am only doing this to do performance measurements on the phone.
Can anyone recommend a good way of accomplishing this? How can I have the server continually sending a large amount of data? Without the intermittent behaviour of reading a line from a file, then sending those bytes... then reading another line and sending those ones.
Ideas? Cheers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不需要发送文件,只需发送数据块即可。
You don't need to send a file, you could just send a block of data.
您可以有一个大小为 1024 的字节数组,并循环地将其一遍又一遍地发送到套接字。数据不需要是唯一的。如果您觉得 KB 对您来说不够大,您可以使用更大的数组。
听起来你是在问那里的服务器。您是否也想知道客户的情况?
You could have a byte array of size 1024 and loop sending it out the socket over and over. The data doesn't need to be unique. You could use a larger array if you felt a KB isn't big enough for you.
Sounds like you were asking about the server there. Were you also wondering about the client?