TcpClient - An existing connection was forcibly closed by the remote host

后端 未结 3 1184
一生所求
一生所求 2021-01-05 19:06

The Info

I have been developing a web http server in c# and decided to add a remote console feature. The console can be used from any location and u

3条回答
  •  一整个雨季
    2021-01-05 19:30

    It seems that your client closes the connection after one message.

    responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
    client.Close();
    return responseData; //returns what server writes
    

    If you want to persist the connection you should have a loop on the client similar to the one you have on the server. If you want to establish a new connection every time you should close the stream gracefully on the server and not have a loop like this. You will still need to loop in case the message is longer or you need to specify max length for the command.

提交回复
热议问题