Socket error: An existing connection was forcibly closed by the remote host

I am trying to send data from unity to matlab for further processing. I am using matlab as server and unity as a client. when I run the program no data is sent from unity and i get the following error
Socket error: System.IO.IOException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.
. β€”> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host.
I tried disabling the firewall but no effect.

It would help to see more of your code. This error happens when the host (matlab) closes the connection and the client (unity) cannot send the data. Look into the matlab API. It’s possible they only allow 1 message to be sent and then require you to reconnect by creating a new TcpClient.