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);
}