如果客户端在udp客户端/服务器应用程序中关闭,服务器如何处理 [英] how does the server handles if the client goes down in udp client/server application

查看:427
本文介绍了如果客户端在udp客户端/服务器应用程序中关闭,服务器如何处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的udp服务器应用程序上实现两个功能。

1.创建持续接收来自任何客户端的数据的线程。

2.创建一个在特定时间段后连续在服务器套接字上发送数据的线程,并等待客户端的回复(握手机制)。 (我实现了这一点,以确保每当客户端出现故障时,客户端都不会发回数据,服务器也会知道客户端已关闭。)

我在服务器端创建了两个Sokets这个目的。

First Socket是绑定()ed到INADDR_ANY。

第二个套接字是bind()ed到我的机器IP地址。

客户端的所有发送和接收都是在第一个套接字上完成的。

确保客户端没有停机的握手机制是在第二个插座上完成的。

这种方法是否正确?请告诉我,以便继续我的工作。提前谢谢你。

I wanted two functionalities to be implemented on my udp server application.
1. Creating thread that continuously receives data coming from any client.
2. Creating a thread that continuously sends data on server socket after specific time period and waits for reply from client (handshake mechanism). (I implemented this to make aure that whenever any client goes down, the client does not send back the data and server comes to know that client is down.)
I have created two Sokets on Server side for this purpose.
First Socket is bind()ed to INADDR_ANY.
Second Socket is bind()ed to my Machines IP Address.
All sends and receives from client are done on first socket.
The Handshake mechanism to ensure that the client has not gone down is done on the second socket.
Is this approach correct? Please do let me know, so that I may proceed with my work. Thank you in advance.

推荐答案

通常你让客户端进行轮询。让客户端每隔x分钟发送一次空闲消息。如果服务器没有从客户端听到超过x分钟,它可能会认为客户端已关闭并终止其线程和/或释放其资源。
Usually you let the client do the polling. Let the client send an idle message every x-minutes. If the server hasn''t heard from a client for more than x-minutes it may assume that the client is down and termintate its thread and/or free its resources.


这篇关于如果客户端在udp客户端/服务器应用程序中关闭,服务器如何处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆