简体   繁体   English

在TCP连接中…Java(数据包)

[英]In a tcp connection… Java (Packets)

When I have a TCP connection that uses packets.. (Server / Client Application) Should I keep sending a packet back and forth (Between the server and client) just to see if the connection is alive or is that unnecessary? 当我有一个使用数据包的TCP连接时。(服务器/客户端应用程序)是否应该继续来回发送数据包(在服务器和客户端之间),只是为了查看连接是否有效还是不必要? like a KeepAlive packet.. 就像一个KeepAlive数据包。

another question is does it make a huge difference (performance wise) if I send an int (DataOutputStream) though a stream instead of sending a Packet object (ObjectOutputStream) which has like an average of 5 fields at least 3 methods and some getters and setters? 另一个问题是,如果我通过一个流发送一个int(DataOutputStream)而不是发送一个Packet Object(ObjectOutputStream),它具有平均5个字段,至少3个方法以及一些getter和setter方法,那么它是否会产生巨大的影响(在性能方面)? ? would it make such a big difference performance wise? 会在性能上有很大的不同吗?

Yeap. 叶氏。 This is called heartbeat. 这称为心跳。 This help recevier of heartbeat to detect if there is problem in connection. 这有助于检测心跳,以检测连接是否存在问题。 Regarding the second part, if you try to send the object than it need to be deserialize and serialze. 关于第二部分,如果您尝试发送对象,则需要反序列化和序列化它。 This will surely have the impact on performance. 这肯定会对性能产生影响。 If you want to know the performance from network lag percpective than it should not be much difference. 如果您想从网络延迟角度了解性能,则应该没有太大区别。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM