public ConnectionService(Session session, UserAuthArgs auth) : base(session) { Contract.Requires(auth != null); _auth = auth; // Send keep-alives if no incoming messages within 5 seconds _keepAliveTimer = new KeepAliveTimer(5000, SendKeepAlive); _session.Disconnected += (ss, ee) => { _keepAliveTimer.Dispose(); }; }
private void SetUpDisconnectedState() { ConnectionInfo = null; ActiveChats.Clear(); SessionID = null; while (SearchRequests.Count > 1) { SearchRequests.Pop(); } _clientEventId = 1; KeepAliveTimer.Stop(); }
public void AfterConnectionInit(bool success) { if (!success) { IsConnected = false; ConnectButtonVisible = true; ConnectButtonText = "Error"; Task.Run(() => { Thread.Sleep(3000); ConnectButtonText = "Connect"; }); return; } IsConnected = true; ConnectButtonText = "Connected!"; Task.Run(() => { Thread.Sleep(3000); ConnectButtonVisible = false; }); //Initialize KeepAlive timer if (KeepAliveTimer != null) { KeepAliveTimer.Dispose(); } KeepAliveTimer = new Timer(new TimerCallback((o) => { Client.SendCommand("whoami"); }), null, 1000 * KeepAliveSeconds, 1000 * KeepAliveSeconds); //Start economy timer EconomyManager.Instance.StartTickTimer(); (MyClientId, MyChannelId) = Client.GetWhoAmI(); Client.GetClientList(false); Client.GetChannelList(false); //Register for: No-Move, Door Client.RegisterEventCallback(typeof(NotifyClientMovedEvent), OnClientMoved); //Register for: Chat Commands Client.RegisterEventCallback(typeof(NotifyTextMessageEvent), OnTextMessageEvent); }
static void Main(string[] args) { /************ Create node object ************/ RegisterType type = RegisterType.TaskManager; byte parallelThreads = 5; string[] problems = { "DVRP" }; NetworkNode node = new NetworkNode(type, parallelThreads, problems); //NetworkNode node = new NetworkNode(); /************ Setup connection ************/ string inputLine = ""; foreach (string arg in args) { inputLine += arg + " "; } InputParser inputParser = new InputParser(inputLine); inputParser.ParseInput(); IPAddress address = inputParser.Address; int port = inputParser.Port; SmartConsole.PrintLine("I'm a " + node.Type, SmartConsole.DebugLevel.Advanced); NetworkClient client = new NetworkClient(address, port); /************ Setup Logic modules ************/ // system tracker SystemTracker systemTracker = new SystemTracker(node); MessageHandler messageHandler = new MessageHandler(systemTracker, client); MessageProcessor messageProcessor = new MessageProcessor(messageHandler, client, node); node.MessageProcessor = messageProcessor; /************ Init all threads ************/ for (int i = 0; i < parallelThreads; i++) { node.TaskThreads[i] = new TaskThread(i, problems[0], messageProcessor, (int)node.Id); } /************ Register ************/ client.Connect(); SmartConsole.PrintLine("Sending Register message", SmartConsole.DebugLevel.Advanced); messageProcessor.Communicate(node.ToRegisterMessage()); KeepAliveTimer keepAliveTimer = new KeepAliveTimer(messageProcessor, systemTracker); /************ Start Logic modules ************/ keepAliveTimer.Start(); Object mutex = new Object(); // TODO Thread pool waiting lock (mutex) { Monitor.Wait(mutex); } }
static void Main(string[] args) { RegisterType type = RegisterType.ComputationalClient; byte parallelThreads = 5; string[] problems = { "DVRP" }; SolveRequestMessage solveRequestMessage = new SolveRequestMessage(); string inputLine = ""; foreach (string arg in args) { inputLine += arg + " "; } InputParser inputParser = new InputParser(inputLine); inputParser.ParseInput(); IPAddress address = inputParser.Address; int port = inputParser.Port; NetworkNode node = new NetworkNode(type, parallelThreads, problems) { Timeout = CLIENT_REQUEST_FREQUENCY }; SmartConsole.PrintLine("ComputationalClient starting work", SmartConsole.DebugLevel.Advanced); NetworkClient client = new NetworkClient(address, port); for (; ;) { /*************** Register *****************/ doWork = true; SmartConsole.PrintLine("Type in a file path", SmartConsole.DebugLevel.Advanced); String filePath = Console.ReadLine(); solveRequestMessage = loadDataFromDisc(filePath); /****** setup logic modules *****************/ SystemTracker systemTracker = new SystemTracker(node); MessageHandler messageHandler = new MessageHandler(systemTracker, client); MessageProcessor messageProcessor = new MessageProcessor(messageHandler, client, node); KeepAliveTimer keepAliveTimer = new KeepAliveTimer(messageProcessor, systemTracker); messageHandler.keepAliveTimer = keepAliveTimer; node.MessageProcessor = messageProcessor; /************ send solve request *****************/ client.Connect(); messageProcessor.Communicate(solveRequestMessage); COMP_TIME = DateTime.Now; while (doWork) { Thread.Sleep(1000); } /*Object mutex = new Object(); * * lock (mutex) * { * Monitor.Wait(mutex); * }*/ } }