English 中文(简体)
IPC:为每个请求连接还是保持插座打开?
原标题:IPC: Connect for each request or keep socket open?

我计划使用套接字(本地TCP)在两个进程(本地运行)之间进行通信。一个进程将充当服务器,但两个进程都异步地相互发送消息。我应该在进程的生命周期内保持套接字连接打开,还是为每个请求重新连接?

如果我保持本地套接字打开,是否会出现任何问题?

最佳回答

保持插座打开

这是一个更简单的选项,并且您不需要(从客户端的角度)打开一个新套接字或(从服务器的角度)接受一个新客户端的开销。

问题回答

如果它只是一个客户端,那么您应该保持套接字打开,但要准备好在出现错误时重新连接(例如,用户可能已经重置了网络接口,因此不能保证连接是活动的)。如果您有许多客户端,请在非活动超时一定时间后使用断开连接。这将使您摆脱非活动、挂起或“丢失”的客户端(那些已经过去但没有关闭套接字的信号的客户端)。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签