private void ConnectAndUpdateServerList() { DispatchHandler.Instance.AddHandler <ServersMsg>(ProcessServersMsg); DispatchHandler.Instance.AddHandler <InterChatCommandMsg>(ProcessInterChatCommandMsg); try { #if DEBUG _session.Connect("127.0.0.1", Configuration.PylonPort); #else _session.Connect(Configuration.PylonHost, Configuration.PylonPort); #endif _session.StartReceive(); _session.Send(new RequestServerMsg()); UpdateUi(() => timerRefresh.Enabled = true); } catch (Exception exception) { UpdateUi(() => { ShowError("Cannot connect to xelina: {0}", exception.Message); textAccountName.Enabled = false; listViewServers.Enabled = false; buttonInterChat.Enabled = false; buttonStartGame.Enabled = false; }); } }
private void Reconnect() { try { _session = MessageSessionManager.Instance.CreateSession(); #if DEBUG _session.Connect("127.0.0.1", Configuration.PylonPort); #else _session.Connect(Configuration.PylonHost, Configuration.PylonPort); #endif _session.StartReceive(); _session.Send(new InterChatLoginMsg { Name = _userName }); return; } catch { Task.Delay(5000).ContinueWith(_ => Reconnect()); } }
private void ConnectionLoop() { while (true) { try { _event.Reset(); Logger.Write("Try to connect Pylon({0}:{1})", Configuration.PylonHost, Configuration.PylonPort); _session = MessageSessionManager.Instance.CreateSession(); _session.Connect(Configuration.PylonHost, Configuration.PylonPort); Task.Factory.StartNew(_session.StartReceive); _session.Send(new ServerMsg { Host = Configuration.HostAddress, Port = Configuration.Port, Name = Configuration.ServerName }); Logger.Write("Pylon Connected."); _event.WaitOne(); } #if DEBUG catch (Exception e) { Logger.Write("Cannot connect to Pylon"); Logger.Write(e); Thread.Sleep(RetryInterval); } #else catch { Logger.Write("Cannot connect to Pylon"); Thread.Sleep(RetryInterval); } #endif } // ReSharper disable FunctionNeverReturns }