Results 1 to 5 of 5

Thread: Create An IRC Client

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    23

    Create An IRC Client

    Hey guys

    I am wondering if anyone has a tutorial or source code to help me get started with creating a IRC Client that will connect to a IRC Server. I just want to make a pretty GUI to modernize it a bit and add some more features etc purely for educational reasons & because I need a new project.

    If anyone has a tutorial or source code that would be great. This is a couple of steps up from my last project so I will need a guide to get me started etc. I have been searching on various sites etc but have found nothing so far.

    Thanks,
    Luke

  2. #2

    Re: Create An IRC Client

    You should start with something simpler when dealing with Sockets. There's a lot of things that need to be done with the IRC protocol (it's pretty nasty) and trying to make a client is a hard deal.

    I recommend reading up on how Sockets work and possibly make a small server-client system before taking on the IRC protocol.

  3. #3
    Fanatic Member BlindSniper's Avatar
    Join Date
    Jan 2011
    Location
    South Africa
    Posts
    865

    Re: Create An IRC Client

    The IRC Protocol isn't really "Nasty", it's quite simple actually, all messages have the same format. An optional prefix, a command and parameters. With that being said there are lots of messages, which would be the only "Nasty" part of the protocol.
    For more info on the protocol:
    http://www.mirc.com/rfc2812.html
    http://www.irchelp.org/irchelp/rfc/rfc2812.txt

    But I also agree with formlesstree, you do need a good understanding of sockets to make a client, and since you want a GUI the sockets parts will need to be multithreaded which is not a simple task.
    So in my opinion you should first learn sockets completely and then multithreading and then how to apply multithreading to sockets. Only then should you consider making a client

    If you need help specifically with the IRC protocol PM me and/or make a thread. I have a good understanding of the basics of the protocol.

    Useful CodeBank Entries of mine
    Expand Function
    Code Compiler
    Sudoku Solver
    HotKeyHandler Class

    Read this to get Effective help on VBForums
    Hitchhiker's Guide to Getting Help at VBF

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    23

    Re: Create An IRC Client

    Ok guys so, I have kind of got a little basic IRC client going in a console app, I just want to get it working and then make the GUI... I am just having one problem, I cant do anything on it.. as you can see I can it says I am connecting to it but it doesn't seem to receive messages or let me send them..

    If any of you can help that would be great! I followed this tutorial except the code they have requires some modifications to get it right, my version is below:

    vb Code:
    1. Imports System
    2. Imports System.Net
    3. Imports System.Net.Sockets
    4. Imports System.Text
    5.  
    6. Module Module1
    7.     Dim sock As Socket
    8.     Dim server As String
    9.     Dim channel As String
    10.     Dim nick As String
    11.  
    12.     Dim cout As System.IO.TextWriter = Console.Out
    13.     Dim cin As System.IO.TextReader = Console.In
    14.  
    15.     Sub Main()
    16.         cout.WriteLine("My IRC Bot")
    17.         cout.Write(vbNewLine)
    18.         cout.Write("Server name: ")
    19.         server = cin.ReadLine
    20.         cout.Write("Channel: ")
    21.         Channel = cin.ReadLine
    22.         cout.Write("Nickname: ")
    23.         nick = cin.ReadLine
    24.  
    25.         Dim iph As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(server)
    26.         Dim ipe As New System.Net.IPEndPoint(iph.AddressList(0), 6667)
    27.         sock = New System.Net.Sockets.Socket(ipe.Address.AddressFamily, Net.Sockets.SocketType.Stream, Net.Sockets.ProtocolType.Tcp)
    28.         sock.Connect(ipe)
    29.  
    30.         send("NICK " & nick)
    31.         send("USER " & nick & " 0 * :" & nick)
    32.         send("JOIN " & Channel)
    33.         send("MODE " & nick & " +iw")
    34.  
    35.         Do While sock.Connected = True
    36.             Dim mail As String = recv()
    37.             cout.WriteLine(mail)
    38.         Loop
    39.     End Sub
    40.  
    41.     Sub send(ByVal msg As String)
    42.         msg &= vbCr & vbLf
    43.         Dim data() As Byte = System.Text.ASCIIEncoding.UTF8.GetBytes(msg)
    44.         sock.Send(data, msg.Length, SocketFlags.None)
    45.     End Sub
    46.  
    47.     Function recv() As String
    48.         Dim data(4096) As Byte
    49.         sock.Receive(data, 4096, SocketFlags.None)
    50.         Dim mail As String = System.Text.ASCIIEncoding.UTF8.GetString(data)
    51.         If mail.Contains(" ") Then
    52.             If mail.Substring(0, 4) = "PING" Then
    53.                 Dim pserv As String = mail.Substring(mail.IndexOf(":"), mail.Length - mail.IndexOf(":"))
    54.                 pserv = pserv.TrimEnd(Chr(0))
    55.                 mail = "PING from " & pserv & vbNewLine & "PONG to " & pserv
    56.                 send("PONG " & pserv)
    57.             ElseIf mail.Substring(mail.IndexOf(" ") + 1, 7) = "PRIVMSG" Then
    58.                 Dim tmparr() As String = Nothing
    59.                 mail = mail.Remove(0, 1)
    60.                 tmparr = mail.Split("!")
    61.                 Dim rnick As String = tmparr(0)
    62.                 tmparr = mail.Split(":")
    63.                 Dim rmsg As String = tmparr(1)
    64.                 mail = "msg: " & rnick & ">" & rmsg
    65.             End If
    66.         End If
    67.         If mail.LastIndexOf(vbLf) > -1 Then
    68.             mail = mail.TrimEnd(Chr(0))
    69.             mail = mail.Remove(mail.LastIndexOf(vbLf), 1)
    70.             mail = mail.Remove(mail.LastIndexOf(vbCr), 1)
    71.         End If
    72.         Return mail
    73.     End Function
    74. End Module

  5. #5

    Re: Create An IRC Client

    Well of course you can't do anything, you are always receiving. The program is stuck in an infinite loop! Spin off a new thread to handle the reading or it'll never work itself out.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width