IPC:为每个请求连接或保持套接字打开? [英] IPC: Connect for each request or keep socket open?
问题描述
我打算使用套接字(本地TCP)在两个进程之间进行通信(在本地运行)。一个进程将充当服务器,但两个进程以异步方式向彼此发送消息。我应该保持套接字连接在进程的生命周期开放,或重新连接每个请求吗?
I am planning to use sockets (local TCP) to communicate between two processes (running locally). One process will act as a server, but both processes send messages to each other asynchronously. Should I keep the socket connection open for the lifetime of the processes, or re-connect for each request?
如果我保留一个本地套接字打开?
Are there any problems that may occur if I keep a local socket open?
推荐答案
保持套接字打开
它是更简单的选项,你不需要承担开启新套接字(从客户端的角度)或接受一个新的客户端(从服务器的角度)的开销。
Its the simpler option and you don't incur in the overhead of opening a new socket (from the client point of view) or accepting a new client (from server point of view).
这篇关于IPC:为每个请求连接或保持套接字打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!