Results 1 to 3 of 3

Thread: Bind IP-Endpoint to Socket

  1. #1
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2018
    Posts
    2
    Rep Power
    0

    Bind IP-Endpoint to Socket

    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:

    Code:
    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 by TBMSam; 12-12-2018 at 7:18 AM. Reason: does not take code tags

  2. #2
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2018
    Posts
    2
    Rep Power
    0
    Unfortunately I shared the wrong picture I am sorry. My cmd -> /ipconfig-settings are as follows:
    own_ip.png

  3. #3
    .NET Framework
    .NET 4.5
    Join Date
    Apr 2011
    Location
    Norway
    Posts
    434
    Rep Power
    111
    Use IPAddress.Any instead. The code can also be simplified with UdpClient class:
    var client = new UdpClient(55555);
    client.Client.ReceiveBufferSize = 120;
    [xcode=c#] code here [/xcode] - see bbcode list or use formatting buttons in posting editor.

    Visual Studio Community 2017

Similar Threads

  1. Question Try to bind DataTable to DataGrid and filter it in best practice
    By hed bisker in forum Windows Presentation Foundation (WPF)
    Replies: 1
    Last Post: 08-26-2018, 1:54 PM
  2. Send local file to rest api upload endpoint
    By hversemann in forum ASP.NET General Discussion
    Replies: 0
    Last Post: 08-28-2017, 11:26 AM
  3. How to bind a result of condition to a combobox?
    By Socarsky in forum Windows Forms
    Replies: 10
    Last Post: 04-02-2014, 2:48 AM
  4. Help with Socket is needed
    By Luckself in forum Net / Sockets
    Replies: 0
    Last Post: 06-06-2013, 10:46 AM
  5. socket error
    By veenanisha in forum Net / Sockets
    Replies: 0
    Last Post: 05-24-2011, 1:38 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •