[英]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.