vietyka2020
vietyka2020
CC#
Created by vietyka2020 on 2/13/2024 in #help
Need help with my server-client application
Hello, I am creating a server - client programm using Tcp. However, I am encoutering a problem where I gets an error called: System.IO.IOException: 'Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..' from the server while loop each time after I have received a message notifying whether I had entered a correct username and a correct password. The following is the while loop i am talking about
while ((count = stream.Read(bytes, 0, bytes.Length)) != 0)
{
data = System.Text.Encoding.ASCII.GetString(bytes, 0, count);
string[] parts = data.Split(',');

if (parts.Length >= 3)
{
string examCode = parts[0];
string username = parts[1];
int password = int.Parse(parts[2]);

resultExamCode = SearchForExamCode(examCode);
resultUsername = SearchForUsername(username);

if (resultExamCode.Equals("Not found") ||
resultExamCode.Equals("Not found") ||
password != 12345678)
{
result = "There is an incorrect field from your inputted information, re-enter again!";

} else
{
result = "Success";
}
}

Byte[] msg = System.Text.Encoding.ASCII.GetBytes(result);
stream.Write(msg, 0, msg.Length);
}
while ((count = stream.Read(bytes, 0, bytes.Length)) != 0)
{
data = System.Text.Encoding.ASCII.GetString(bytes, 0, count);
string[] parts = data.Split(',');

if (parts.Length >= 3)
{
string examCode = parts[0];
string username = parts[1];
int password = int.Parse(parts[2]);

resultExamCode = SearchForExamCode(examCode);
resultUsername = SearchForUsername(username);

if (resultExamCode.Equals("Not found") ||
resultExamCode.Equals("Not found") ||
password != 12345678)
{
result = "There is an incorrect field from your inputted information, re-enter again!";

} else
{
result = "Success";
}
}

Byte[] msg = System.Text.Encoding.ASCII.GetBytes(result);
stream.Write(msg, 0, msg.Length);
}
9 replies