Vote count:
0
If the host goes offline, they lose all connected clients and they don't automatically connect back due to my break; in the code. If I do not do the break; in the code, it mass spams the same user connected over and over. Basically, if the host goes down in the middle of a session, I want the clients to automatically reconnect once the host goes back up.
Here's my code
public static void tryConnect()
{
while (true)
{
try
{
TcpClient client = new TcpClient();
client.Connect(IPAddress.Parse(host), port);
NetworkStream stream = client.GetStream();
string user = Environment.UserName;
byte[] userByte = Encoding.ASCII.GetBytes(user);
stream.Write(userByte,0,userByte.Length);
stream.Close();
client.Close();
break;
}
catch
{
Thread.Sleep(10000);
}
}
asked 31 secs ago
Aucun commentaire:
Enregistrer un commentaire