Is it possible to keep sockets open infinite time

前端 未结 3 1711
心在旅途
心在旅途 2021-01-25 15:39

I\'m new to network programming. I\'m interested is it possible to establish network connection via sockets between Java server and C client and keep the connection open infinit

3条回答
  •  甜味超标
    2021-01-25 16:14

    Is is theoretically possible to keep server sockets open an indefinitely long amount of time; however, it is not possible to do so with the client-side socket. The main reason why is because the client side socket is dependent on the server side socket handling the data, and the server socket may close the connection.

    While it might be possible to keep a connection open indefinitely, practical aspects typically ensure that such sockets don't stay open forever. Network outages, misconfiguration in intermediate routers, exhaustion of bandwidth, lack of computing power, etc. all collude to ensure that point to point connections are at best temporary.

    Note that a server side socket is a socket that receives requests to connect (spawning off connections which have their own return sockets), so it can be open even when there are no connections. If you think of a socket as an open connection to another computer, you will need to reorient your thinking to have server sockets make any sense.

提交回复
热议问题