I have a client and a server and it works locally on my computer. Although when I deploy it all clients are rejected with the following 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
at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at SlientServer_v2_1.ConnectionHandle.SendRequestInformation(Client target, Int32 messageId) in c:\Users\Ya\Dropbox\Private\Visual Studio\Projects\SlientServer_v2_1\SlientServer_v2_1\ConnectionHandle.cs:line 136
Here is my code for sending data:
public static void SendRequestInformation(Client target, int messageId)
{
NetworkStream stream = target.getClientSocket().GetStream();
byte[] byteData = null;
switch (messageId)
{
case 0:
byteData = Encoding.ASCII.GetBytes("ping");
break;
case 1:
byteData = Encoding.ASCII.GetBytes("hand");
break;
case 3:
byteData = Encoding.ASCII.GetBytes("osif");
break;
case 4:
byteData = Encoding.ASCII.GetBytes("idle");
break;
case 5:
byteData = Encoding.ASCII.GetBytes("cpus");
break;
case 6:
byteData = Encoding.ASCII.GetBytes("mine");
break;
case 2:
byteData = Encoding.ASCII.GetBytes("rein");
break;
case 7:
byteData = Encoding.ASCII.GetBytes("bcac");
break;
}
try
{
byte[] bufferedToSend = new byte[byteData.Length + 4];
byte[] lengthOfSend = BitConverter.GetBytes(byteData.Length);
Array.Copy(lengthOfSend, bufferedToSend, 4);
byteData.CopyTo(bufferedToSend, 4);
--- This is 136 ---- stream.Write(bufferedToSend, 0, bufferedToSend.Length);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
ClientHandle.RemoveFromClientPool(target, "Unable to reach Client");
}
}
I've looked at the following for clues, no dice An existing connection was forcibly closed by the remote host
The first message send is probably case 1.