Example #1
0
        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
        }
Example #2
0
        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());
            }
        }