在通过UDP发送数据之前,C#检查客户端 [英] C# check client before sending data via UDP

查看:126
本文介绍了在通过UDP发送数据之前,C#检查客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!



我正在编写小应用程序,通过udp发送文本数据。



在服务器端,我有一个用于发送和接收数据的异步UDP套接字。

在客户端,我有相同的异步UDP套接字。

当客户端向服务器发送数据时,然后立即退出应用程序而不等待服务器的响应,服务器端发生错误。



错误:强制关闭现有连接由远程主机。



我明白这个错误意味着我可以在服务器上重新创建套接字,但是此时发送或接收数据的所有客户也会看到错误并丢失一些数据。



要修复它我可以创建单独的套接字用于发送和接收但在我看来,这是错误的解决方案。关于这个问题的另一个想法是检查死亡客户端,但我不知道我怎么做到这一点。



也许有人对这个问题有任何想法?



我是c#的新手....不要发誓=)

Hello all!

I'm writing small app for sending text data via udp.

On server side i have one async UDP socket for sending and receiving data.
On client side i have same async UDP socket.
When the client sends data to the server, then immediately exit the application without waiting for a response from the server, an error occurs on the server side.

Error: An existing connection was forcibly closed by the remote host.

I understand that this error means and I can re-create the socket on the server, but all clients who at this moment send or receive data also will see an error and will lose some data.

To fix it I can create separate sockets for sending and receiving.But it seems to me that this is the wrong solution. Another idea about this problem is check deads clients, but i don't know how i can do this.

Maybe someone has any idea about this problem?

i'm new in c#....do not swear much =)

推荐答案

为什么你甚至使用UDP?根据您的描述,您不能丢失数据。



UDP不保证数据到达目的地,甚至不保证数据包显示正确订单!



您描述的内容需要TCP,而不是UDP。



UDP用于广播无连接数据容忍数据包丢失的流媒体视频。



如果您正在与服务器进行对话,请改用TCP。
Why are you even using UDP? From what you describe, you cannot lose data.

UDP doesn't guarantee the data gets to the destination and doesn't even guarantee the packets show up in the correct order!

What you describe requires TCP, not UDP.

UDP is used to broadcast connectionless data that tolerates packet loss, such a streaming video.

If you're holding a conversation with a server, use TCP instead.


这篇关于在通过UDP发送数据之前,C#检查客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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