简体   繁体   English

如何在UDPClient上获取远程端点?

[英]How can i get a remote endpoint at UDPClient?

I'm making a server app, and i need to know, from which address message has come to the server. 我正在制作服务器应用程序,我需要知道从哪个地址消息发送到服务器。 At Socket class has a RemoteEndPoint to get know where message come from. Socket类中,有一个RemoteEndPoint可以知道消息从何而来。 Is it have some solution to find where message come from at UDPClient class? UDPClient类中找到消息来自哪里有解决方案吗? I searched web, but didn't find something about it. 我搜索了网络,但未找到任何相关信息。

As you have not posted any code, this is a simplified example, that should get the job done: 由于您尚未发布任何代码,因此这是一个简化的示例,应该可以完成工作:

UdpClient udp = new UdpClient(5050);
private void Listen()
{
    while (true)
    {
         IPEndPoint anyIP = new IPEndPoint(IPAddress.Any, 0);
         byte[] recData = udp.Receive(ref anyIP);
         string ip = anyIP.Address.ToString() //this is client IP address
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带有UDPClient.EndReceive和ref远程端点参数的Observable.FromAsyncPattern - Observable.FromAsyncPattern with UDPClient.EndReceive and ref remote endpoint Parameter 如何找出导致SocketException的端点,UdpClient - How to find out which endpoint caused the SocketException, UdpClient C#可以给UdpClient设置超时时间吗? - Can I set the timeout for UdpClient in C#? 如何使异步UdpClient接收并获得响应超时? - How to Timeout an Async UdpClient Receive AND Get a Response? 当端点不可用时,UdpClient 不会失败 - UdpClient not failing when endpoint is unavailable 当UdpClient正在侦听不再可用的地址时,我该如何处理? - How can I handle when a UdpClient is listening on an address which is no longer available? 使用端点路由和 MVC 时,如何从 Endpoint.RequestDelegate 获取 IActionContextAccessor? - How can I get the IActionContextAccessor from the Endpoint.RequestDelegate when using Endpoint Routing and MVC? UDPClient流略有延迟。 我可以加快速度吗? - UDPClient stream is slightly delayed. Can I speed it up? 首次建立后如何更改UdpClient端口(通常只允许每个套接字地址使用一次) - How can I change a UdpClient port after I established it a first time (Only one usage of each socket address is normally permitted) UdpClient C#从特定端点开始接收 - UdpClient C# BeginReceive from a specific EndPoint
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM