Sam Mettenmeyer

Sam Mettenmeyer

  • NA
  • 108
  • 10.5k

Bind IP-Endpoint to Socket

Dec 12 2018 4:32 AM
Hello everyone, 

on my local network, there is a udp broadcast sent by a server every 5 seconds. It is 120 Byte long.

I am trying to set a socket in order to consume it:

  1. IPAddress ip = IPAddress.Parse("192.168.127.162");  
  2. IPEndPoint ipe = new IPEndPoint(ip, 55555);  
  3. Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)  
  4. {  
  5.    ReceiveBufferSize = 120  
  6. };  
  7. socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 30);  
  8. socket.Bind(ipe);   
My local cmd -> /ipconfig shows the following:


Unfortunately, I am getting error message in the binding line:

System.Net.Sockets.SocketException: The requested address is not valid in this context

 

What could be the problem? Wrong IP format? Or am I doing something wrong when instantiating?

Would be really happy if someone could help me anyhow.

Best regards


Answers (1)