Is it possible to keep sockets open infinite time

前端 未结 3 1673
心在旅途
心在旅途 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.

    0 讨论(0)
  • 2021-01-25 16:14

    Nothing is infinite (in computing), but you can keep a socket connection open as long as both applications are running.

    0 讨论(0)
  • 2021-01-25 16:14

    This is more a plea than an answer, but as a user I've found sockets drop all the time. You can't keep them open indefintely. When a socket closes unexpectedly, please (A) let the user know the connection has been dropped and (B) make it real easy to reestablish the same connection. Okay, this involved games, but I've had clients that wouldn't admit the server was gone and servers that wouldn't recognise I was the same person as the one with the dropped connection.

    0 讨论(0)
提交回复
热议问题