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); } } }
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(); } }
public void SetListener(INetworkListener listener) { if (listener != null) { this.listener = listener; State = ConnectingState.NeverConnect; Connect(); } }
/// <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); }
private void Connector_SessionOpened(object sender, Mina.Core.Session.IoSessionEventArgs e) { session = e.Session; State = ConnectingState.Connected; }
private void Connector_SessionClosed(object sender, IoSessionEventArgs e) { State = ConnectingState.Disconnected; }