views:

39

answers:

2

I am making IRC chat client and I am wanting to grab the user list or simply the user count, how can I go about doing this. This is the method I'm using to connect to the 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

I have no idea where to start, any help would be much appreciated.

+2  A: 

The IRC-protocol is defined in RFC2812: http://tools.ietf.org/html/rfc2812

Send the "NAMES #currentchannel" - command ( http://tools.ietf.org/html/rfc2812#section-3.2.5 ) and you will receive a list of all visible users. This list can be counted and voilà - there you got your user-count

Erik
I was unaware of that command, much appreciated but how can I read from the IRC server output?
Ben
imho you have the "reader" (New StreamReader(stream)) where you should receive the "answers" of the server
Erik
When attempting to retrieve reader.ReadToEnd the application fails to respond ("Not Responding").
Ben
I'm not with VB - but you have to check your reader in a way like this: if (reader.dataAvailable()) {data = reader.readAll();} But I think this is another question - therefor you should perhaps open another question, since this is a VB-depending question and not a IRC-protocoll question.
Erik
Don't use `ReadToEnd`, it will read until the stream is closed. You need to read data as it is available and then extract complete records from that data. Look at `BeginRead` or `Read`. If you try to read more data from the socket than is currently available, your read will block until that data arrives.
lrm
A: 

Start by reading the the specification for IRC, it is RFC 2812.

You'll want to use the NAMES message. Here is the appropriate section from the RFC.

lrm