Question Bind IP-Endpoint to Socket

TBMSam

New member
Joined
Dec 12, 2018
Messages
3
Programming Experience
Beginner
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:

C#:
IPAddress ip = IPAddress.Parse("192.168.127.162");
IPEndPoint ipe = new IPEndPoint(ip, 55555);
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)
{
    ReceiveBufferSize = 120 
};
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 30);
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
 
Last edited:
Unfortunately I shared the wrong picture I am sorry. My cmd -> /ipconfig-settings are as follows:
own_ip.png
 
Use IPAddress.Any instead. The code can also be simplified with UdpClient class:
var client = new UdpClient(55555);
client.Client.ReceiveBufferSize = 120;
 

Latest posts

Back
Top Bottom