C# Getting sender address from UDP message

后端 未结 3 1472
北恋
北恋 2020-12-20 08:18

I have an embedded Ethernet interface (Lantronix XPort) that responds to a UDP broadcast with its identifying information.

I am able to multicast the \"magic packet\

相关标签:
3条回答
  • 2020-12-20 08:43

    Take a look at ReceiveFrom instead of Receive, it will let you pass in a reference to an Endpoint.

    0 讨论(0)
  • 2020-12-20 08:54

    What about Asynchronous socket?I didn't find any way to get the remote IP address. (Asynchronous method ReceiveFromAsync is my only option in wp8)

    0 讨论(0)
  • 2020-12-20 09:03

    EndPoint remote_ep = new IPEndPoint(IPAddress.Any, 0); // Use ReceiveFrom instead of sendSocket.Receive(data, SocketFlags.None);
    sendSocket.ReceiveFrom(data, ref remote_ep);

    i think it works for IP but it fails for port number if you would notice

    try chaging 0 to something else like 6530 4expl

    it system will would generate it's random port number

    Any ideas to why is it ?

    P.S. Any ideas how can i change my user name here .... ?

    FOUND IT : the abstract class only needed for representation of port it is in value not out

    since there's no bind done before hand this operation ref EndPoint needed to represent the sender. Meaning that it is there to show senders port and IP not to specify from where to get the communication. And EndPoint instantiation is really just a formality seems like it is overriden by system with senders address anyway. I think it has to do somethign with the way UDP protocol works. But all in all the ref EndPoint is there only shows where u got the packet from and only it does not specify where u want u'r commuicatino to be from.

    0 讨论(0)
提交回复
热议问题