예제 #1
0
파일: Networking.cs 프로젝트: o0oteam/Ph-m
        private void Connect()
        {
            var connector = new AsyncSocketConnector();

            connector.FilterChain.AddLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Encoding.UTF8)));
            connector.FilterChain.AddLast("logger", new LoggingFilter());

            connector.ConnectTimeoutInMillis          = 10000;
            connector.SessionConfig.KeepAlive         = true;
            connector.SessionConfig.SendBufferSize    = 1024;
            connector.SessionConfig.ReceiveBufferSize = 1024 * 3;
            connector.MessageReceived += Connector_MessageReceived;
            connector.MessageSent     += Connector_MessageSent;
            connector.SessionOpened   += Connector_SessionOpened;
            connector.SessionClosed   += Connector_SessionClosed;
            IPAddress address = IPAddress.Parse(IpAddress);

            for (var i = 0; i < 5; i++)
            {
                try
                {
                    var connectFuture = connector.Connect(new IPEndPoint(address, 6667));//.Await();
                    State = ConnectingState.Connecting;
                    Debug.LogWarning("Session: " + connectFuture.Session);
                    return;
                }catch (Exception e)
                {
                    Debug.LogWarning("Error on connect: \n" + e.StackTrace);
                }
            }
        }
예제 #2
0
        public void OnConnect(object sender, EventArgs e)
        {
            // We need an XID and Password to connect to the server.
            if (String.IsNullOrEmpty(Settings.Password))
            {
                Events.Error(this, ErrorType.MissingPassword, ErrorPolicyType.Deactivate);
            }
            else if (String.IsNullOrEmpty(Settings.Id))
            {
                Events.Error(this, ErrorType.MissingJID, ErrorPolicyType.Deactivate);
            }
            else if (String.IsNullOrEmpty(Settings.Hostname))
            {
                Events.Error(this, ErrorType.MissingHost, ErrorPolicyType.Deactivate);
            }
            else
            {
#if DEBUG
                Events.LogMessage(this, LogType.Info, "Connecting to {0}", Connection.Hostname);
#endif

                // Set the current state to connecting and start the process.
                State = new ConnectingState(this);
                State.Execute();
            }
        }
예제 #3
0
파일: Networking.cs 프로젝트: o0oteam/Ph-m
 public void SetListener(INetworkListener listener)
 {
     if (listener != null)
     {
         this.listener = listener;
         State         = ConnectingState.NeverConnect;
         Connect();
     }
 }
예제 #4
0
        /// <inheritdoc />
        public void Connect(Jid jid, string password)
        {
            if (jid is null)
            {
                throw new ArgumentNullException(nameof(jid));
            }

            _logger.Log(LogLevel.Debug, $"Connecting to server for {jid}");
            Id = jid;
            Password = password;
            State = new ConnectingState();
            State.Execute(this);
        }
예제 #5
0
파일: Networking.cs 프로젝트: o0oteam/Ph-m
 private void Connector_SessionOpened(object sender, Mina.Core.Session.IoSessionEventArgs e)
 {
     session = e.Session;
     State   = ConnectingState.Connected;
 }
예제 #6
0
파일: Networking.cs 프로젝트: o0oteam/Ph-m
 private void Connector_SessionClosed(object sender, IoSessionEventArgs e)
 {
     State = ConnectingState.Disconnected;
 }