简体   繁体   English

Java:使用DataOutputStream向套接字写入会减慢然后停止

[英]Java: Writing to socket with DataOutputStream slows down, then stops

while (true) {
    loc = getLocationOnScreen();

    out.writeLong((long)loc.getX());
    out.writeLong((long)loc.getY());
    out.flush();

    i++;
    System.out.println(i);

}

This code will merrily go along for about 3 seconds, before it slows, then stops. 这段代码会缓慢运行约3秒钟,然后变慢,然后停止。

i ends at about 16491 , never to continue increasing. i在大约16491处结束,永不继续增加。 What's going on here? 这里发生了什么?

It is slowing down because , at the receiving end you might be doing long task using the value sent by you , before reading the next value. 它之所以变慢是因为,在接收端,在读取下一个值之前,您可能会使用您发送的值来执行长任务。 So the rate at which the other side is reading the data is smaller than the rate at which you are sending data to that. 因此,另一端读取数据的速率小于您向其发送数据的速率。 This keeps filling the receiving buffer at the other side and sending buffer at sender side. 这将继续在另一侧填充接收缓冲区,并在发送方填充发送缓冲区。 Eventually when both buffers are filled completely the transmission of data is halted. 最终,当两个缓冲区都完全装满时,数据传输将停止。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 应用程序变慢并停止响应尝试加载相机(Java,Libgdx) - App slows down and stops responding trying to load camera(Java, Libgdx) java,用DataOutputStream写入数据大小 - java, writing data size with DataOutputStream 使用 DataOutputStream 写入文件的 Java 不起作用 - Java writing into file with DataOutputStream not working Java将BufferedReader,DataOutputStream和Sockets传递给可运行的线程类会导致在写入流时导致套接字异常 - Java passing BufferedReader, DataOutputStream and Sockets to a runnable thread class leads to socket exception upon writing to stream Java-DataOutputStream的writeLong方法并写入十六进制 - Java - writeLong method of DataOutputStream and writing hex Java 套接字停止从 DataOutputStream 读取 - Java socket stop reading from DataOutputStream 软件导致连接异常终止:写入DataOutputStream时套接字写入错误 - Software caused connection abort: socket write error while writing to DataOutputStream 使用DataOutputStream向Server Socket写消息到Client Socket的消息仅在关闭Client Socket后才发送,为什么? - Writing messages to client socket using DataOutputStream to Server Socket only sent after closing the Client Socket why? Java DataOutputStream不会写入所有消息(TCP套接字) - Java DataOutputStream doesnt write all messages ( TCP Socket ) Java:另一端通过套接字的DataOutputStream错误(Python) - Java: DataOutputStream through socket is wrong on other side (which is Python)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM