2

I am trying to just create a very simple client/server in C#, basically all i am trying to do at the moment is get the client to connect to the server, which is where I get en error. My server starts fine but when I try and start my client i get this error:

The requested address is not valid in this context
  at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00000] in <filename unknown>:0
  at Client.Client.Main (System.String[] args) [0x00000] in <filename unknown>:0

The basic client I have right now goes as follows

        try
        {
            IPAddress ipAddress = IPAddress.Parse("0.0.0.0");
            IPEndPoint remoteEP = new IPEndPoint(ipAddress, 8001);

            Socket sender = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            try
            {
                sender.Connect(remoteEP);                    

                Console.WriteLine("Connected to: " + remoteEP);

                byte[] msg = Encoding.ASCII.GetBytes("Testing");

                sender.Send(msg);


                sender.Shutdown(SocketShutdown.Both);
                sender.Close();

            }

            catch (Exception e)
            {
                Console.WriteLine(e.Message + "\n" + e.StackTrace);
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message + "\n" + e.StackTrace);
        }
0

1 Answer 1

5

That is not a valid IP address. For localhost (your own machine) this is what you want

   IPAddress ipAddress = IPAddress.Parse("127.0.0.1");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.