维护与服务器端服务的套接字连接是否对向桌面应用程序发送通知不利?

huangapple go评论96阅读模式
英文:

Is maintaining a socket connection to a server-side service bad for sending notifications to desktop applications?

问题

我目前正在进行一个小型的业余项目,以学习一些新技术。我的计划是创建一个聊天应用程序,客户端使用WPF构建,服务器端使用Java构建。

我好奇的是在发送和接收消息方面应该采取什么方法。我目前的想法是使用套接字连接将用户登录,然后保持该连接以在用户收到消息时发送通知。许多人可能会在计算机上运行这样的应用程序很多小时,那么维护套接字连接是否不好?如果是这样,是否有其他方法我应该考虑?

英文:

I'm currently working on a semi-small spare time project to learn some new technologies. My plan is to create a chat application, client-side being built in WPF, and server-side with Java.

What I'm curious about is what approach I should take to sending and receiving messages. My current idea is to log the user in using a socket connection, and then maintain that connection to send that user notifications when he/she receives a message. Many people might have an application such as this run for many hours on their computer, so is maintaining a socket connection bad? If so, is there another approach I should consider instead?

答案1

得分: 2

TCP套接字连接可以保持很长时间,但最终会中断,例如当连接两端的网络接口被重新配置或服务器或客户端软件重新启动时。

为了检测中断,一些协议包括一个"心跳"机制。客户端和服务器定期交换一条消息,其中说:"我还在,你在吗?"如果客户端一段时间内没有收到服务器的心跳,它可以假定连接已经中断并尝试重新连接。

英文:

TCP socket connections can be left open for a long time, but will break eventually, for example when the network interfaces on either side of the connection are reconfigured, or when the server or client side software is restarted.

To detect breakage, some protocols include a "heartbeat" mechanism. The client and server regularly exchange a message that says "I'm still here, are you there?" If the client doesn't receive a heartbeat from the server for a while, it can assume that the connection has been broken and try to reconnect.

huangapple
  • 本文由 发表于 2020年8月13日 23:33:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/63398458.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定