当前位置: 首页>>代码示例>>C#>>正文


C# IrcClient.Connect方法代码示例

本文整理汇总了C#中IrcClient.Connect方法的典型用法代码示例。如果您正苦于以下问题:C# IrcClient.Connect方法的具体用法?C# IrcClient.Connect怎么用?C# IrcClient.Connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IrcClient的用法示例。


在下文中一共展示了IrcClient.Connect方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IrcClientList

 public static void IrcClientList()
 {
     IrcClient irc = new IrcClient();
     irc.OnRawMessage += new EventHandler<IrcEventArgs>(IrcClientListCallback);
     irc.Connect(SERVER, PORT);
     irc.Login(NICK, REALNAME);
     irc.RfcList(CHANNEL);
     irc.Listen();
 }
开发者ID:FreeApophis,项目名称:sharpIRC,代码行数:9,代码来源:benchmark.cs

示例2: Connect

        public void Connect(string server, IrcRegistrationInfo registrationInfo)
        {
            // Create new IRC client and connect to given server.
            var client = new IrcClient();
            client.FloodPreventer = new IrcStandardFloodPreventer(4, 2000);
            client.Connected += IrcClient_Connected;
            client.Disconnected += IrcClient_Disconnected;
            client.Registered += IrcClient_Registered;

            // Wait until connection has succeeded or timed out.
            using (var connectedEvent = new ManualResetEventSlim(false))
            {
                client.Connected += (sender2, e2) => connectedEvent.Set();
                client.Connect(server, false, registrationInfo);
                if (!connectedEvent.Wait(10000))
                {
                    client.Dispose();
                    ConsoleUtilities.WriteError("Connection to '{0}' timed out.", server);
                    return;
                }
            }

            // Add new client to collection.
            this.allClients.Add(client);

            Console.Out.WriteLine("Now connected to '{0}'.", server);
        }
开发者ID:djeebus,项目名称:MusicHub,代码行数:27,代码来源:IrcBot.cs

示例3: ClassInitialize

        public static void ClassInitialize(TestContext testContext)
        {
            stateManager = new TestStateManager<IrcClientTestState>();

            // Create IRC clients.
            ircClient1 = new IrcClient();
#if DEBUG
            ircClient1.ClientId = "1";
#endif
            ircClient1.FloodPreventer = new IrcStandardFloodPreventer(4, 2000);
            ircClient1.Connected += ircClient1_Connected;
            ircClient1.ConnectFailed += ircClient1_ConnectFailed;
            ircClient1.Disconnected += ircClient1_Disconnected;
            ircClient1.Error += ircClient1_Error;
            ircClient1.ProtocolError += ircClient1_ProtocolError;
            ircClient1.Registered += ircClient1_Registered;
            ircClient1.MotdReceived += ircClient1_MotdReceived;
            ircClient1.NetworkInformationReceived += ircClient1_NetworkInformationReceived;
            ircClient1.ServerVersionInfoReceived += ircClient1_ServerVersionInfoReceived;
            ircClient1.ServerTimeReceived += ircClient1_ServerTimeReceived;
            ircClient1.ServerLinksListReceived += ircClient1_ServerLinksListReceived;
            ircClient1.ServerStatsReceived += ircClient1_ServerStatsReceived;
            ircClient1.WhoReplyReceived += ircClient1_WhoReplyReceived;
            ircClient1.WhoIsReplyReceived += ircClient1_WhoIsReplyReceived;
            ircClient1.WhoWasReplyReceived += ircClient1_WhoWasReplyReceived;
            ircClient1.ChannelListReceived += ircClient1_ChannelListReceived;

            ircClient2 = new IrcClient();
#if DEBUG
            ircClient2.ClientId = "2";
#endif
            ircClient2.Connected += ircClient2_Connected;
            ircClient2.ConnectFailed += ircClient2_ConnectFailed;
            ircClient2.Disconnected += ircClient2_Disconnected;
            ircClient2.Error += ircClient2_Error;
            ircClient2.ProtocolError += ircClient2_ProtocolError;
            ircClient2.Registered += ircClient2_Registered;

            // Create CTCP clients over IRC clients.
            ctcpClient1 = new CtcpClient(ircClient1);
            ctcpClient1.ClientVersion = clientVersionInfo;
            ctcpClient1.PingResponseReceived += ctcpClient1_PingResponseReceived;
            ctcpClient1.VersionResponseReceived += ctcpClient1_VersionResponseReceived;
            ctcpClient1.TimeResponseReceived += ctcpClient1_TimeResponseReceived;
            ctcpClient1.ActionReceived += ctcpClient1_ActionReceived;

            ctcpClient2 = new CtcpClient(ircClient2);
            ctcpClient2.ClientVersion = clientVersionInfo;
            ctcpClient2.PingResponseReceived += ctcpClient2_PingResponseReceived;
            ctcpClient2.VersionResponseReceived += ctcpClient2_VersionResponseReceived;
            ctcpClient2.TimeResponseReceived += ctcpClient2_TimeResponseReceived;
            ctcpClient2.ActionReceived += ctcpClient2_ActionReceived;

            // Initialize wait handles for all events.
            GetAllWaitHandlesFields().ForEach(fieldInfo => fieldInfo.SetValue(null, new AutoResetEvent(false)));

            // Nick name length limit on irc.freenode.net is 16 chars.
            Func<string> getRandomUserId = () => Guid.NewGuid().ToString().Substring(0, 8);

            serverPassword = Properties.Resources.ServerPassword;
            if (string.IsNullOrEmpty(serverPassword))
                serverPassword = null;
            nickName1 = userName1 = string.Format(Properties.Resources.NickNameFormat, getRandomUserId());
            nickName2 = userName2 = string.Format(Properties.Resources.NickNameFormat, getRandomUserId());
            realName = Properties.Resources.RealName;

            Debug.WriteLine("Client users have real name '{0}'", realName);
            Debug.WriteLine("Client 1 user has nick name '{0}' and user name '{1}'.", nickName1, userName1);
            Debug.WriteLine("Client 2 user has nick name '{0}' and user name '{1}'.", nickName2, userName2);

            stateManager.SetStates(IrcClientTestState.Client1Initialized, IrcClientTestState.Client2Initialized);
            ircClient1.Connect(Properties.Resources.ServerHostName, false, new IrcUserRegistrationInfo()
                {
                    Password = serverPassword,
                    NickName = nickName1,
                    UserName = userName1,
                    RealName = realName,
                });
            ircClient2.Connect(Properties.Resources.ServerHostName, false, new IrcUserRegistrationInfo()
                {
                    Password = serverPassword,
                    NickName = nickName2,
                    UserName = userName2,
                    RealName = realName,
                });
        }
开发者ID:GJiin,项目名称:meridian59-dotnet,代码行数:86,代码来源:IrcClientTestSet.cs

示例4: menuItemConnect_Click

        private void menuItemConnect_Click(object sender, System.EventArgs e)
        {
            try
            {
                AppendText(tabControlChatTabs.SelectedTab.Text, "notice", " -!- Attempting connection to " + User.server + ":" + User.port.ToString() + "\n");

                if (File.Exists("ignore"))
                {
                    using (StreamReader sr = new StreamReader("ignore"))
                    {
                        string line = null;

                        while ((line = sr.ReadLine()) != null)
                        {
                            alIgnoredHosts.Add(line.ToString());
                        }
                    }
                }

                irc = new IrcClient();
                irc.SendDelay = 200;
                irc.AutoRetry = false;
                irc.ChannelSyncing = true;

                irc.OnTopic += new TopicEventHandler(irc_OnTopic);
                irc.OnDisconnected += new SimpleEventHandler(irc_OnDisconnected);
                irc.OnDeop += new DeopEventHandler(irc_OnDeop);
                irc.OnOp += new OpEventHandler(irc_OnOp);
                irc.OnOwner += new OwnerEventHandler(irc_OnOwner);
                irc.OnHalfOp += new HalfOpEventHandler(irc_OnHalfOp);
                irc.OnProtect += new ProtectEventHandler(irc_OnProtect);
                irc.OnDeOwner += new DeOwnerEventHandler(irc_OnDeOwner);
                irc.OnDeHalfOp += new DeHalfOpEventHandler(irc_OnDeHalfOp);
                irc.OnDeProtect += new DeProtectEventHandler(irc_OnDeProtect);
                irc.OnDevoice += new DevoiceEventHandler(irc_OnDevoice);
                irc.OnVoice += new VoiceEventHandler(irc_OnVoice);
                irc.OnWho += new WhoEventHandler(irc_OnWho);
                irc.OnModeChange += new MessageEventHandler(irc_OnModeChange);
                irc.OnUserModeChange += new MessageEventHandler(irc_OnUserModeChange);
                irc.OnUnban += new UnbanEventHandler(irc_OnUnban);
                irc.OnBan += new BanEventHandler(irc_OnBan);
                irc.OnKick += new KickEventHandler(irc_OnKick);
                irc.OnQueryAction += new ActionEventHandler(irc_OnQueryAction);
                irc.OnQuit += new QuitEventHandler(irc_OnQuit);
                irc.OnNickChange += new NickChangeEventHandler(irc_OnNickChange);
                irc.OnChannelAction += new ActionEventHandler(irc_OnChannelAction);
                irc.OnReadLine += new ReadLineEventHandler(irc_OnReadLine);
                irc.OnJoin += new JoinEventHandler(irc_OnJoin);
                irc.OnPart += new PartEventHandler(irc_OnPart);
                irc.OnQueryNotice += new MessageEventHandler(irc_OnQueryNotice);
                irc.OnChannelMessage += new MessageEventHandler(irc_OnChannelMessage);
                irc.OnQueryMessage += new MessageEventHandler(irc_OnQueryMessage);

                if (irc.Connect(User.server, User.port))
                {
                    irc.Login(User.username, Application.Name + " " + Application.Version);
                    irc.Join(User.channel);

                    if (irc.Connected)
                    {
                        menuItemConnect.Enabled = false;
                        menuItemDisconnect.Enabled = true;

                        threadIrcConnection = new Thread(new ThreadStart(IRCListenThread));
                        threadIrcConnection.Start();
                    }
                    else
                    {
                        AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "[");
                        AppendText(tabControlChatTabs.SelectedTab.Text, "time", DateTime.Now.ToShortTimeString().ToString());
                        AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "] ");
                        AppendText(tabControlChatTabs.SelectedTab.Text, "notice", " -!- Unable to connect to " + User.server + ":" + User.port.ToString() + "\n");
                    }
                }
                else
                {
                    AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "[");
                    AppendText(tabControlChatTabs.SelectedTab.Text, "time", DateTime.Now.ToShortTimeString().ToString());
                    AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "] ");
                    AppendText(tabControlChatTabs.SelectedTab.Text, "notice", " -!- A connection to " + User.server + ":" + User.port.ToString() + " could not be established.\n");
                }
            }
            catch (Exception ex)
            {
                User.ErrorLog(ex.ToString());
            }
        }
开发者ID:gavinkendall,项目名称:psychat,代码行数:87,代码来源:ChatForm.cs


注:本文中的IrcClient.Connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。