从IRC获取用户数

时间:2010-07-08 13:43:21

标签: vb.net list count irc

我正在制作IRC聊天客户端,我想抓住用户列表或只是用户数量,我该怎么做呢。这是我用来连接IRC的方法:

Private Sub IRCConnect()
        Dim stream As NetworkStream
        Dim irc As TcpClient
        Dim reader As StreamReader
        Try
            irc = New TcpClient(SERVER, PORT)
            stream = irc.GetStream()
            reader = New StreamReader(stream)
            writer = New StreamWriter(stream)
            ' Start PingSender thread
            Dim ping As New PingSender
            ping.Start()
            writer.WriteLine(USER)
            writer.Flush()
            writer.WriteLine("NICK " & Config.Nickname)
            writer.Flush()
            writer.WriteLine("JOIN " & Config.Channel & " " & Config.ChanPass)
            writer.Flush()
            txtView.Text = txtView.Text & ">Connected successfully." & vbNewLine
            HighlightPhrase(txtView, "Connected successfully.", Color.Lime)
            Thread.Sleep(2000)
        Catch Ex As Exception
            ' Show the exception, sleep for a while and try to establish a new connection to irc server
            txtView.Text = txtView.Text & ">ERROR: Unexpected error occured: " & Ex.ToString & vbNewLine
            HighlightPhrase(txtView, "Unexpected error occured: " & Ex.ToString, Color.Red)
        End Try
    End Sub

我不知道从哪里开始,我们非常感谢任何帮助。

2 个答案:

答案 0 :(得分:4)

IRC协议在RFC2812中定义:http://tools.ietf.org/html/rfc2812

发送“NAMES #currentchannel” - 命令(http://tools.ietf.org/html/rfc2812#section-3.2.5),您将收到所有可见用户的列表。这个列表可以计算并且有效 - 你得到了你的用户数

答案 1 :(得分:1)

首先阅读IRC的规范it is RFC 2812

您需要使用NAMES消息。来自RFC的Here is the appropriate section