Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8817389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:50:08+00:00 2026-06-14T04:50:08+00:00

I’m tinkering with golang and my first code is a simple IRC bot with

  • 0

I’m tinkering with golang and my first code is a simple IRC bot with the following code:

package main

import ("net"
        "log"
        "bufio"
        "fmt"
        "net/textproto"
      )
type Bot struct{
        server string
        port string
        nick string
        user string
        channel string
        pass string
        pread, pwrite chan string
        conn net.Conn
}

func NewBot() *Bot {
        return &Bot{server: "irc.freenode.net",
                    port: "6667",
                    nick: "subsaharan",
                    channel: "#rapidsms", 
                    pass: "",
                    conn: nil,
                    user: "blaze"}
}
func (bot *Bot) Connect() (conn net.Conn, err error){
  conn, err = net.Dial("tcp",bot.server + ":" + bot.port)
  if err != nil{
    log.Fatal("unable to connect to IRC server ", err)
  }
  bot.conn = conn
  log.Printf("Connected to IRC server %s (%s)\n", bot.server, bot.conn.RemoteAddr())
  return bot.conn, nil
}



func main(){
  ircbot := NewBot()
  conn, _ := ircbot.Connect()
  conn.Write([]byte("NICK " + ircbot.nick))
  conn.Write([]byte("JOIN " + ircbot.channel))
  defer conn.Close()

  reader := bufio.NewReader(conn)
  tp := textproto.NewReader( reader )
  for {
        line, err := tp.ReadLine()
        if err != nil {
            break // break loop on errors    
        }
        fmt.Printf("%s\n", line)
    }

}

When I run this code I get the following output on the terminal:

2012/11/12 13:31:20 Connected to IRC server irc.freenode.net (193.219.128.49:6667)
:sendak.freenode.net NOTICE * :*** Looking up your hostname...
:sendak.freenode.net NOTICE * :*** Checking Ident
:sendak.freenode.net NOTICE * :*** Couldn't look up your hostname
:sendak.freenode.net NOTICE * :*** No Ident response
ERROR :Closing Link: 127.0.0.1 (Connection timed out)

Any reason why the connection keeps timing out?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:50:09+00:00Added an answer on June 14, 2026 at 4:50 am

    All commands sent to an IRC server have a maximum of 255 512 bytes and must be terminated with a carriage return and linefeed \r\n.

    conn.Write([]byte("NICK " + ircbot.nick + "\r\n"))
    conn.Write([]byte("JOIN " + ircbot.channel + "\r\n"))
    

    Additionally, freenode expects the USER command to be first thing it sees from you.

    conn.Write([]byte("USER "+ircbot.nick+" 8 * :" + ircbot.nick + "\r\n"))
    conn.Write([]byte("NICK " + ircbot.nick + "\r\n"))
    conn.Write([]byte("JOIN " + ircbot.channel + "\r\n"))
    

    As a side note, you can make your life a little easier by using fmt.Fprintf to format and send the data:

    fmt.Fprintf(conn, "USER %s 8 * :%s\r\n", ircbot.nick, ircbot.nick)
    fmt.Fprintf(conn, "NICK %s\r\n", ircbot.nick)
    fmt.Fprintf(conn, "JOIN %s\r\n", ircbot.channel)
    

    The first parameter of fmt.Fprintf must be any type that satisfies the io.Writer interface. The net.Conn implementations all do this. As such you can pass them into any function which expects an io.Writer (or io.Reader for that matter) implementation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.