Java EOFException服务器/客户端TCP应用程序 [英] Java EOFException Server/Client TCP application

查看:178
本文介绍了Java EOFException服务器/客户端TCP应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中正在运行2个线程.一种用于检查传入的数据包,一种用于处理和发送数据包.他们俩都在同一流中做到这一点.

I am running 2 threads in my applciation. One to check for incoming packets and one to process and send packets. They both do it on the SAME STREAM.

示例1:

while (connection open) {
    in.readObject() instanceof ...
}

示例2:

while (connection open) {
    processPacket(in)
}

我很确定EOFException是线程尝试同时使用流时.这不是一个恒定的EOF,但是就像每隔一秒钟我得到一个EOF一样,其余的都可以正常工作.因此,这就是为什么我怀疑它们重叠并尝试同时使用流的原因.

I'm pretty sure EOFException is when the threads try and use the stream at the same time. It's not a constant EOF but only like every 1 second I get an EOF the rest works fine. So that's why I suspect that they overlap and try to use the stream at the same time.

如果这是问题所在,谁知道在保持当前更新速度并使用两个线程的情况下,如何使他们一次又一次同步呢?

If that is the problem, anyone know how do I synchronize them to do it after another while still keeping the current update speed and using two threads?

我需要两个线程,因为对传入请求的检查会在一行中等待,直到接收到数据包为止,并且我需要服务器不断发送进程并检查数据包.

I need two threads because the check for incoming waits in a line until a packet gets recived and I need the server to constantly send process and check for packets.

如何修复EOFException?

How do I fix the EOFException?

推荐答案

如果收到EOFException,通常意味着另一端挂断了.您通常会在阅读方面获得这些.

If your getting an EOFException, it typically means the other side hung up. You usually get these on the read side.

这是类似的问题

问题实际上是为什么插座关闭了.可能由于多种原因,服务器端的可编程计时器在X分钟内不检查任何数据,防火墙关闭了连接,网络中断等.

Edit 1: The question is really why is the socket closed. It can be for any number of reasons, a programmable timer on the server side checking for no data within X minutes, a firewall closing the connection, a network interruption, etc..

这篇关于Java EOFException服务器/客户端TCP应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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