Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Compact Framework / April 2006

Tip: Looking for answers? Try searching our database.

Determine remote IP when using UDP Listener?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Benjamin Lukner - 13 Apr 2006 15:03 GMT
Hi!

I'm using System.Net.Sockets.Socket.BeginReceive() to listen for
incoming UDP packets. When my callback method is called, how do I
determine who has sent the packet? I have to know if my CE terminal has
sent the message itself or if it came over WLAN from a remote machine
and what's its IP address...

Kind regards and Happy Easter

Benjamin
Paul G. Tobey [eMVP] - 13 Apr 2006 17:25 GMT
Read the help for BeginReceiveFrom()/EndReceiveFrom().  This topic is
covered specifically there.

Paul T.

> Hi!
>
[quoted text clipped - 7 lines]
>
> Benjamin
Benjamin Lukner - 21 Apr 2006 15:19 GMT
Hi Paul,

I'm sorry, but I can't find anything in the help.
I've created a new class "stateObject", fill it, pass it and extract the
socket on Endreceive.

But I can't read the RemoteEndPoint property when using _UDP_.

I'm afraid I need another hint... :-/

Kind regards,

Benjamin Lukner

> Read the help for BeginReceiveFrom()/EndReceiveFrom().  This topic is
> covered specifically there.
[quoted text clipped - 4 lines]
>>itself or if it came over WLAN from a remote machine and what's its IP
>>address...
Paul G. Tobey [eMVP] - 21 Apr 2006 16:01 GMT
I don't think that you  read the help that I pointed you to.  From
BeginReceiveFrom:

-----
This method reads data into the buffer parameter, and captures the remote
host endpoint from which the data is sent. For information on how to
retrieve this endpoint, refer to EndReceiveFrom. This method is most useful
if you intend to asynchronously receive connectionless datagrams from an
unknown host or multiple hosts. In these cases, BeginReceiveFrom will read
the first enqueued datagram received into the local network buffer. If the
datagram you receive is larger than the size of buffer, the BeginReceiveFrom
method will fill buffer with as much of the message as is possible, and
throw a SocketException. If you are using an unreliable protocol, the excess
data will be lost. If you are using a reliable protocol, the excess data
will be retained by the service provider and you can retrieve it by calling
the BeginReceiveFrom method with a large enough buffer.

-----

and from EndReceiveFrom:

-----

To identify the originating host, extract the EndPoint and cast it to an
IPEndPoint. Use the IPEndPoint.Address method to obtain the IP address and
the IPEndPoint.Port method to obtain the port number.

-----

Don't know how to make it any clearer than that...

Paul T.

> Hi Paul,
>
[quoted text clipped - 18 lines]
>>>message itself or if it came over WLAN from a remote machine and what's
>>>its IP address...
Benjamin Lukner - 21 Apr 2006 16:34 GMT
Hi Paul,

> I don't think that you  read the help that I pointed you to.  From
> BeginReceiveFrom:
[...]
> Don't know how to make it any clearer than that...

You were right, I'd read the help on BeginReceive/EndReceive...

I'd seen before that there is a BeginreceiveFrom function, but I don't
know the sender's IP address and thought the function won't work for my
purposes.

But now I realized that I can pass IPAddress.Any to that function.
Works great, thanks!

Kind regards,

Benjamin Lukner

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.