I am testing a simple websocket server with the following code in a Console application with .Net8. Can anyone please help to check what could be wrong? Thank you
TcpListener server = new TcpListener(IPAddress.Parse("127.0.0.1"), 8080);
server.Start();
Console.WriteLine("Server has started on 127.0.0.1:8080.{0}Waiting for a connection…", Environment.NewLine);
TcpClient client = server.AcceptTcpClient();
Console.WriteLine("A client connected.");
NetworkStream stream = client.GetStream();
while (true)
{
while (!stream.DataAvailable) ;
byte[] bytes = new byte[client.Available];
stream.Read(bytes, 0, bytes.Length);
Console.WriteLine(System.Text.Encoding.Default.GetString(bytes));
}
However, when I try to connect to the server with Postman, I keep getting connecting
state and cannot send message as follow
I tried to debug with console but there is nothing in it
Here is what I can see from the websocket server console