The requsted address is invalid in this context when i am trying to listing for specific IP

pravin Gavande 1 Reputation point

I am trying to connect the medical equipment with LAN cable. and i am using C# based windows application to receive the data which machine is sending when any blood sample runs in machine

As per my requirement i need to use TCP listner to recevie the data which machine is sending.. but when i connected medical equipment(ip address - with my laptop(ip address- throw lan then i am getting error message like "The requested address is invalid in this context".

(I already checked both sender ip is able to ping from laptop as well).

Then i read may articale and find that need to use IPADDRESS.ANY. But this will not help me.

Means sender machine says ///when cursor comes to start the listener then it is throwing the error msg. please check network connection...

pasting my code here.. please check and help me with this

//Code start

//Posting my complete code

          string response = String.Empty;
            IPAddress ipAddress = IPAddress.Parse("");
            Socket client;
            TcpListener listener = new TcpListener(ipAddress,5100);
            byte[] data;

            while (true)

              client = listener.AcceptSocket();
              var childSocketThread = new Thread(() =>
                    data = new byte[4096];
                    int size = client.Receive(data);
                    ASCIIEncoding encoder = new ASCIIEncoding();
                    string returndata = Encoding.UTF8.GetString(data);
                    // Get response
                    string responce = responcemsg();
                    //Custom save funtion

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,640 questions
.NET Internet of things
.NET Internet of things
.NET: Microsoft Technologies based on the .NET software framework.Internet of things: A concept that aims to extend the benefits of the regular internet, including constant connectivity, remote control ability, and data sharing, to goods in the physical world.
29 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Alberto Poblacion 1,556 Reputation points

    Wrong address. If your laptop is you cannot listen on The address that you pass to the Listener is your local address (your machine could potentially have several addresses, and you tell it n which one of them it should be listening for any other machine to connect). It is not the address of the machine from which you want to receive a connection.

    Edit: If you want your computer to listen on all of its addresses, so that you don't have to bother to tell the TcpListener which one to use, you can pass the option IPAddress.Any.

    1 person found this answer helpful.