/// <summary> /// Handles the keepalive packets every minute to remain in the server /// </summary> private void KeepAlive(Object adrr) { while (!stop) { try { Thread.Sleep(1000 * 30); KeepAliveInstruction ki = new KeepAliveInstruction(); List <KailleraInstruction> alive = new List <KailleraInstruction>(); alive.Add(ki); IPEndPoint adr = (IPEndPoint)adrr; log.Info("Sending keepalive packer to " + adr.ToString() + "with seq number " + ki.serial.ToString()); //Race condition here, should lock to prevent it if (stop) { break; } UDPMessenger.SendMessages(alive, adr, client); } catch (ThreadInterruptedException) { break; } } }
public void Start(Object o) { connectionClosed += EndConnection; WindowMngr = o as KailleraNET.KailleraWindowController; if (initConnection()) { //Send Logon messager = new UDPMessenger(ip); messager.AddMessages(new UserLogonInstruction(username + "\0", 1)); messager.SendMessages(client); //Begin recieving and processing loop alive = new Thread(KeepAlive); //alive.Start(ip); /* System.Timers.Timer KeepAliveTimer = new System.Timers.Timer(); * KeepAliveTimer.Elapsed += new System.Timers.ElapsedEventHandler(KeepAliveSameThread); * KeepAliveTimer.Interval = 60000; * KeepAliveTimer.AutoReset = true; * KeepAliveTimer.Enabled = true; */ alive.Start(ip); Recieve(); } else //If we didn't connect successfully, return to the main window { KailleraWindowController.getMgr().connectionFailed(); } }
/// <summary> /// Only here for debugging purposes, not used otherwise. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void KeepAliveSameThread(object sender, ElapsedEventArgs e) { KeepAliveInstruction ki = new KeepAliveInstruction(); List <KailleraInstruction> alive = new List <KailleraInstruction>(); alive.Add(ki); log.Info("Sending keepalive packer to " + ip.ToString() + "with seq number " + ki.serial.ToString()); UDPMessenger.SendMessages(alive, ip, client); }
public void Start(Object o) { connectionClosed += EndConnection; WindowMngr = o as KailleraNET.KailleraWindowController; if (initConnection()) { //Send Logon messager = new UDPMessenger(ip); messager.AddMessages(new UserLogonInstruction(username + "\0", 1)); messager.SendMessages(client); //Begin recieving and processing loop alive = new Thread(KeepAlive); //alive.Start(ip); /* System.Timers.Timer KeepAliveTimer = new System.Timers.Timer(); KeepAliveTimer.Elapsed += new System.Timers.ElapsedEventHandler(KeepAliveSameThread); KeepAliveTimer.Interval = 60000; KeepAliveTimer.AutoReset = true; KeepAliveTimer.Enabled = true; */ alive.Start(ip); Recieve(); } else //If we didn't connect successfully, return to the main window { KailleraWindowController.getMgr().connectionFailed(); } }