473,395 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Problem gettin a RemoteEndPoint from a UDP packet

PH
Hi guys!

I need to get the remote EndPoint from when I receive packets when
listening in a local port in my computer.

I'm using UDP (connection-less) so I only bind the socket to my
localEndPoint, I do not Bind(), Connect() to a RemoteEndPoint.

I'm using BeginReceive() to listen and receive from connection
Asynchronously.

In this way how do I get the RemoteEndPoint?

Thanks guys!




Mar 8 '06 #1
10 6917
PH,

Don't you make a call to Accept somewhere? The socket that is returned from that call should have the RemoteEndPoint populated and you should be able to get the information about the client from there.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"PH" <no****@nospam.com> wrote in message news:00b201c642d3$03a18ed0$0e01a8c0@m1...
Hi guys!



I need to get the remote EndPoint from when I receive packets when listening in a local port in my computer.

I'm using UDP (connection-less) so I only bind the socket to my localEndPoint, I do not Bind(), Connect() to a RemoteEndPoint.

I'm using BeginReceive() to listen and receive from connection Asynchronously.



In this way how do I get the RemoteEndPoint?



Thanks guys!











Mar 8 '06 #2
PH


Hi Nicholas, thanks for your answer;

Remember that this is connection-less.

I do not make any kind of connection.

I listen for incoming connections Binding to a localEndPoint. And then
using BeginReceive()

So you think that I can get the RemoteEndPoint in this way?

Thanks again

_____

From: Nicholas Paldino [.NET/C# MVP]
[mailto:mv*@spam.guard.caspershouse.com]
Posted At: Wednesday, March 08, 2006 12:41 PM
Posted To: microsoft.public.dotnet.languages.csharp
Conversation: Problem gettin a RemoteEndPoint from a UDP packet
Subject: Re: Problem gettin a RemoteEndPoint from a UDP packet
PH,

Don't you make a call to Accept somewhere? The socket that is
returned from that call should have the RemoteEndPoint populated and you
should be able to get the information about the client from there.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"PH" <no****@nospam.com> wrote in message
news:00b201c642d3$03a18ed0$0e01a8c0@m1...

Hi guys!

I need to get the remote EndPoint from when I receive packets when
listening in a local port in my computer.

I'm using UDP (connection-less) so I only bind the socket to my
localEndPoint, I do not Bind(), Connect() to a RemoteEndPoint.

I'm using BeginReceive() to listen and receive from connection
Asynchronously.

In this way how do I get the RemoteEndPoint?

Thanks guys!




Mar 8 '06 #3
Ph,

If that is the case, then I would have your clients send the IP information as part of the information they are sending, if you need to identify them.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"PH" <no****@nospam.com> wrote in message news:00c401c642df$c8035680$0e01a8c0@m1...


Hi Nicholas, thanks for your answer;



Remember that this is connection-less.

I do not make any kind of connection.

I listen for incoming connections Binding to a localEndPoint. And then using BeginReceive()



So you think that I can get the RemoteEndPoint in this way?





Thanks again




------------------------------------------------------------------------------

From: Nicholas Paldino [.NET/C# MVP] [mailto:mv*@spam.guard.caspershouse.com]
Posted At: Wednesday, March 08, 2006 12:41 PM
Posted To: microsoft.public.dotnet.languages.csharp
Conversation: Problem gettin a RemoteEndPoint from a UDP packet
Subject: Re: Problem gettin a RemoteEndPoint from a UDP packet


PH,



Don't you make a call to Accept somewhere? The socket that is returned from that call should have the RemoteEndPoint populated and you should be able to get the information about the client from there.



Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"PH" <no****@nospam.com> wrote in message news:00b201c642d3$03a18ed0$0e01a8c0@m1...

Hi guys!



I need to get the remote EndPoint from when I receive packets when listening in a local port in my computer.

I'm using UDP (connection-less) so I only bind the socket to my localEndPoint, I do not Bind(), Connect() to a RemoteEndPoint.

I'm using BeginReceive() to listen and receive from connection Asynchronously.



In this way how do I get the RemoteEndPoint?



Thanks guys!











Mar 8 '06 #4
PH
This is the thing;

I receive a packet, I have to process it, and then I have to send the
response packet back to the same IP and port where the original packet
was coming from.

Having said that, and considering that there is no connection of any
kind between the two machines (needles because is UDP) there has to be a
way out there to do just that.

What do you think?

Thanks Nicholas

_____

From: Nicholas Paldino [.NET/C# MVP]
[mailto:mv*@spam.guard.caspershouse.com]
Posted At: Wednesday, March 08, 2006 1:51 PM
Posted To: microsoft.public.dotnet.languages.csharp
Conversation: Problem gettin a RemoteEndPoint from a UDP packet
Subject: Re: Problem gettin a RemoteEndPoint from a UDP packet
Ph,

If that is the case, then I would have your clients send the IP
information as part of the information they are sending, if you need to
identify them.


--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"PH" <no****@nospam.com> wrote in message
news:00c401c642df$c8035680$0e01a8c0@m1...

Hi Nicholas, thanks for your answer;

Remember that this is connection-less.

I do not make any kind of connection.

I listen for incoming connections Binding to a localEndPoint. And then
using BeginReceive()

So you think that I can get the RemoteEndPoint in this way?

Thanks again


_____
From: Nicholas Paldino [.NET/C# MVP]
[mailto:mv*@spam.guard.caspershouse.com]
Posted At: Wednesday, March 08, 2006 12:41 PM
Posted To: microsoft.public.dotnet.languages.csharp
Conversation: Problem gettin a RemoteEndPoint from a UDP packet
Subject: Re: Problem gettin a RemoteEndPoint from a UDP packet
PH,

Don't you make a call to Accept somewhere? The socket that is
returned from that call should have the RemoteEndPoint populated and you
should be able to get the information about the client from there.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"PH" <no****@nospam.com> wrote in message
news:00b201c642d3$03a18ed0$0e01a8c0@m1...

Hi guys!

I need to get the remote EndPoint from when I receive packets when
listening in a local port in my computer.

I'm using UDP (connection-less) so I only bind the socket to my
localEndPoint, I do not Bind(), Connect() to a RemoteEndPoint.

I'm using BeginReceive() to listen and receive from connection
Asynchronously.

In this way how do I get the RemoteEndPoint?

Thanks guys!




Mar 8 '06 #5
PH,

You will have to make it part of the protocol that the client sends the IP address to get a response from.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"PH" <no****@nospam.com> wrote in message news:00d801c642e2$1a661e60$0e01a8c0@m1...
This is the thing;



I receive a packet, I have to process it, and then I have to send the response packet back to the same IP and port where the original packet was coming from.

Having said that, and considering that there is no connection of any kind between the two machines (needles because is UDP) there has to be a way out there to do just that.



What do you think?



Thanks Nicholas


------------------------------------------------------------------------------

From: Nicholas Paldino [.NET/C# MVP] [mailto:mv*@spam.guard.caspershouse.com]
Posted At: Wednesday, March 08, 2006 1:51 PM
Posted To: microsoft.public.dotnet.languages.csharp
Conversation: Problem gettin a RemoteEndPoint from a UDP packet
Subject: Re: Problem gettin a RemoteEndPoint from a UDP packet


Ph,



If that is the case, then I would have your clients send the IP information as part of the information they are sending, if you need to identify them.


--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"PH" <no****@nospam.com> wrote in message news:00c401c642df$c8035680$0e01a8c0@m1...



Hi Nicholas, thanks for your answer;



Remember that this is connection-less.

I do not make any kind of connection.

I listen for incoming connections Binding to a localEndPoint. And then using BeginReceive()



So you think that I can get the RemoteEndPoint in this way?





Thanks again




----------------------------------------------------------------------------

From: Nicholas Paldino [.NET/C# MVP] [mailto:mv*@spam.guard.caspershouse.com]
Posted At: Wednesday, March 08, 2006 12:41 PM
Posted To: microsoft.public.dotnet.languages.csharp
Conversation: Problem gettin a RemoteEndPoint from a UDP packet
Subject: Re: Problem gettin a RemoteEndPoint from a UDP packet


PH,



Don't you make a call to Accept somewhere? The socket that is returned from that call should have the RemoteEndPoint populated and you should be able to get the information about the client from there.



Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"PH" <no****@nospam.com> wrote in message news:00b201c642d3$03a18ed0$0e01a8c0@m1...

Hi guys!



I need to get the remote EndPoint from when I receive packets when listening in a local port in my computer.

I'm using UDP (connection-less) so I only bind the socket to my localEndPoint, I do not Bind(), Connect() to a RemoteEndPoint.

I'm using BeginReceive() to listen and receive from connection Asynchronously.



In this way how do I get the RemoteEndPoint?



Thanks guys!











Mar 8 '06 #6
Hello PH, I have had a similar problem myself, and I used the same
solution that Nicholas is telling you. If you can have the clients send
their IP address with the packet, that is the best solution. The IP
address can be a simple 4 bytes at the beginning or end of your
packets.

If you need to be able to get RemoteEndPoint information from the
packet, I think you would have to switch to TCP. As far as I know UDP,
since it is connectionless, does not have this information. It could
also be that .NET does not share this information for UDP. All I know
is I ran into the same problem, and now I pre-pend IP address and port
information to the beginning of each of my packages.

Best of luck ~ Justin

Mar 8 '06 #7
PH,
You don't specify exactly how you are using BeginReceive. However if you
pass the Socket in your State object, you should be able to do something like
the following (this is from some Syslog UDP message listening code I have):

EndPoint epSource = new
IPEndPoint(((IPEndPoint)state.remoteEndPoint).Addr ess,((IPEndPoint)state.remoteEndPoint).Port);
string sFromIPAndPort = epSource.ToString(); //ep.ToString();

Hope that helps.
Peter

--
Co-founder,
Eggheadcafe.comhttp://msdn.microsoft.com/wn3/aspx/postui.aspx?mid=34b2004f-e2d3-49af-8848-5969b3cf1a5b&cat=&lang=en&cr=US&guid=&sloc=en-us&dg=microsoft.public.dotnet.languages.csharp&bas e=http://msdn.microsoft.com/newsgroups/default.aspx&bclr=ececec&fclr=000000&sxml=http://msdn.microsoft.com/newsgroups/site.xml&stgxml=http://msdn.microsoft.com/newsgroups/settings.xml&sdgloc=en-US
developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"PH" wrote:
Hi guys!

I need to get the remote EndPoint from when I receive packets when
listening in a local port in my computer.

I'm using UDP (connection-less) so I only bind the socket to my
localEndPoint, I do not Bind(), Connect() to a RemoteEndPoint.

I'm using BeginReceive() to listen and receive from connection
Asynchronously.

In this way how do I get the RemoteEndPoint?

Thanks guys!




Mar 8 '06 #8
PH

Hi Justin, thanks for your reply.
I can't to anything with the incoming packets, because I don't control,
the client. Another thing is that the protocol used works over UDP, so
TCP is not an option.

What's killing me is that obviously there should be a way to accomplish
this.
Think about this, how other people are using UDP to receive packets, and
then send a response back? They can only do this if they know where the
packet is coming from.

Thanks again.


-----Original Message-----
From: JustinC [mailto:ju***********@gmail.com]
Posted At: Wednesday, March 08, 2006 2:58 PM
Posted To: microsoft.public.dotnet.languages.csharp
Conversation: Problem gettin a RemoteEndPoint from a UDP packet
Subject: Re: Problem gettin a RemoteEndPoint from a UDP packet

Hello PH, I have had a similar problem myself, and I used the same
solution that Nicholas is telling you. If you can have the clients send
their IP address with the packet, that is the best solution. The IP
address can be a simple 4 bytes at the beginning or end of your
packets.

If you need to be able to get RemoteEndPoint information from the
packet, I think you would have to switch to TCP. As far as I know UDP,
since it is connectionless, does not have this information. It could
also be that .NET does not share this information for UDP. All I know
is I ran into the same problem, and now I pre-pend IP address and port
information to the beginning of each of my packages.

Best of luck ~ Justin

Mar 8 '06 #9
PH,

They probably know because they have the client tell them (as I have
suggested) in the first place.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"PH" <no****@nospam.com> wrote in message
news:00f901c642ee$e0a61bf0$0e01a8c0@m1...

Hi Justin, thanks for your reply.
I can't to anything with the incoming packets, because I don't control,
the client. Another thing is that the protocol used works over UDP, so
TCP is not an option.

What's killing me is that obviously there should be a way to accomplish
this.
Think about this, how other people are using UDP to receive packets, and
then send a response back? They can only do this if they know where the
packet is coming from.

Thanks again.


-----Original Message-----
From: JustinC [mailto:ju***********@gmail.com]
Posted At: Wednesday, March 08, 2006 2:58 PM
Posted To: microsoft.public.dotnet.languages.csharp
Conversation: Problem gettin a RemoteEndPoint from a UDP packet
Subject: Re: Problem gettin a RemoteEndPoint from a UDP packet

Hello PH, I have had a similar problem myself, and I used the same
solution that Nicholas is telling you. If you can have the clients send
their IP address with the packet, that is the best solution. The IP
address can be a simple 4 bytes at the beginning or end of your
packets.

If you need to be able to get RemoteEndPoint information from the
packet, I think you would have to switch to TCP. As far as I know UDP,
since it is connectionless, does not have this information. It could
also be that .NET does not share this information for UDP. All I know
is I ran into the same problem, and now I pre-pend IP address and port
information to the beginning of each of my packages.

Best of luck ~ Justin

Mar 8 '06 #10
PH
When I run this code, senderRemote returns 0.0.0.0
It should return the remote endpoint, should it?

Thanks

Public Shared Sub ReceiveFrom1()
Dim hostEntry As IPHostEntry = Dns.GetHostEntry(Dns.GetHostName())
Dim endPoint As New IPEndPoint(hostEntry.AddressList(0), 11000)

Dim s As New Socket(endPoint.Address.AddressFamily,
SocketType.Dgram, ProtocolType.Udp)

' Creates an IPEndPoint to capture the identity of the sending host.
Dim sender As New IPEndPoint(IPAddress.Any, 0)
Dim senderRemote As EndPoint = CType(sender, EndPoint)

' Binding is required with ReceiveFrom calls.
s.Bind(endPoint)

Dim msg() As Byte = New [Byte](255) {}
Console.WriteLine("Waiting to receive datagrams from client...")

' This call blocks.
s.ReceiveFrom(msg, senderRemote)
s.Close()

End Sub 'ReceiveFrom1

Mar 8 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Droopy | last post by:
Hi, I try to implement a reusable socket class to send and receive data. It seems to work but I have 2 problems : 1) I rely on Socket.Available to detect that the connection is closed (no...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
2
by: Fernando Barsoba | last post by:
Dear all, I have been posting about a problem trying to encrypt certain data using HMAC-SHA1 functions. I posted that my problem was solved, but unfortunately, I was being overly optimistic. I...
0
by: PH | last post by:
Hi guys! I need to get the remote EndPoint from when I receive packets when listening in a local port in my computer. I'm using UDP (connection-less) so I only bind the socket to my...
2
by: Daniel Lindberg | last post by:
Hi, im a beginner in C# and i just cant seem to get my udp broadcasting to work. What happens is that it just locks down on the Receive call and never gets any data. I have the code for the server...
4
by: Rain | last post by:
Hi, I have this problem in my UDP broadcasting, im a newbie in UDP, any help at all would be very much appreciated. I have a working UDP broadcast that sends and recieves without any problem. I...
10
by: Clayton | last post by:
Hi all, I'm trying to develop a server that listens to incoming calls using the asycnhronous methods BeginAccept / EndAccept. I start the server (till this point it is ok) and few seconds later...
6
by: White Spirit | last post by:
I have the following code to send a packet to a remote socket and receive a response in return: System.Net.Sockets.Socket locSocket = new System.Net.Sockets.Socket (AddressFamily.InterNetwork,...
0
by: gnome5482 | last post by:
I'm having a bit of trouble trying to receive packets from a remote server via udp. My application reads the data coming from the server and puts the data into a textbox. This seems to be working as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.