[英]Reading from socket input stream
I'm trying to determine the best way to transfer data through a socket between a client and server. 我正在尝试确定通过客户端和服务器之间的套接字传输数据的最佳方法。 Currently I have a BufferedReader that reads one character at a time (or however many characters have arrived since the last iteration).
目前,我有一个BufferedReader,它一次读取一个字符(或者,自上次迭代以来,已经到达了许多字符)。 Through each iteration, it pulls the data received so far and puts it into an array.
在每次迭代中,它会将到目前为止收到的数据提取到一个数组中。 When the '|'
当“ |” character is read, it knows that the current instruction is done.
字符被读取,它知道当前指令已完成。
I know what I have so far is grossly inefficient and burns the CPU, but I'm a little unclear as to the differences between all the ways to read from a socket input stream. 我知道到目前为止,我的工作效率非常低下,并且烧毁了CPU,但是对于从套接字输入流读取数据的所有方式之间的差异,我还不清楚。 What would I use to not have to read each character at a time, but rather to wait until the input stream is finished receiving the current instruction (which would be terminated by "\\n")?
我将不必一次读取每个字符,而是等到输入流完成接收当前指令(该指令将以“ \\ n”终止)后使用什么呢?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.