Again me, yes. 5 minute of coding = 1 day trying to fix the code. Here is my code, which throws IOException (Unable to read from stream) only on the second request, the first works fine. The exception is thrown at bytes = sslStream.Read(buffer, 0, buffer.Length);
I've tried to fix this with no results.
Here is the code for request function:
public void SendRequest(string request)
{
byte[] buffer = new byte[2048];
int bytes = -1;
StringBuilder message = new StringBuilder() ;
sslStream.Write(Encoding.ASCII.GetBytes(request + "\r\n"));
do
{
try
{
bytes = sslStream.Read(buffer, 0, buffer.Length);
message.Append(Encoding.ASCII.GetString(buffer, 0, bytes));
}
catch (Exception)
{
throw;
}
} while(!message.ToString().Contains("\n"));
Console.WriteLine(message);
}
Code calling SendRequest()
function:
while((request = Console.ReadLine().ToLower()) != "exit")
{
con.SendRequest(request);
}
If u want full code, check it here: GitHub Repo