By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,403 Members | 891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,403 IT Pros & Developers. It's quick & easy.

Set broadcast source ip-address

P: 3
Hello community,

I'm currently writing a broadcast sender class in C# .NET (using .NET Framework 3.5).

On my computer there are more than one local network interface and if I send a broadcast, the UdpClient class choose "randomly" a source ip-address from a network interface.

Does anybody knows a possibility to set a specific sender ip-address?

Thank you in advance!

Greets from Switzerland,
Giovanni

Expand|Select|Wrap|Line Numbers
  1. IPAddress GroupAddress = IPAddress.Broadcast;
  2. int GroupPort = 11108;
  3. UdpClient sender = new UdpClient();
  4. IPEndPoint groupEP = new IPEndPoint(GroupAddress, GroupPort);
  5. byte[] bytes = Encoding.ASCII.GetBytes("Hello network.. (da08frup3)");
  6. sender.Send(bytes, bytes.Length, groupEP);
  7. sender.Close();
  8.  
inspiration by: http://social.msdn.microsoft.com/forums/en-US/netfxnetcom/thread/16b686d5-7c07-440f-9411-d311f3fb4a2f/
Sep 15 '08 #1
Share this Question
Share on Google+
4 Replies


Plater
Expert 5K+
P: 7,872
I think with UdpClient, you can set your LocalEndPoint maybe?
Sep 15 '08 #2

P: 3
I think with UdpClient, you can set your LocalEndPoint maybe?
That was my first idea, but the property is read-only :( (Note: the LocalEndPoint property is located in the class Socket).

I think the solution must be in the socket layer, but I couldn't see it :(
Sep 15 '08 #3

Plater
Expert 5K+
P: 7,872
Did you see this constructor type:
UdpClient(IPEndPoint localEP)

So you could say:
UdpClient u = new UdpClient(myLocalEP)

See if that works?
Sep 15 '08 #4

P: 3
Did you see this constructor type:
UdpClient(IPEndPoint localEP)

So you could say:
UdpClient u = new UdpClient(myLocalEP)

See if that works?
Dear Plater,

Thank you for your help, now it works!! I was so fixed to find the solution in the Socket class, that I not looked exactly in the UdpClient class..

Sorry for this newbie question..

Sincerelly yours,
Giovanni
Sep 17 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.