Created
November 11, 2014 10:04
-
-
Save goldeneggg/19324dc61debb4199ff0 to your computer and use it in GitHub Desktop.
simple irc client test for go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// +build main_irc2 | |
package main | |
import ( | |
"bufio" | |
"fmt" | |
"net" | |
"net/textproto" | |
"os" | |
) | |
func main() { | |
irc() | |
} | |
// http://stackoverflow.com/questions/13342128/simple-golang-irc-bot-keeps-timing-out | |
func irc() { | |
proto := "tcp" | |
server := "ngircd.localdomain:6667" | |
// dial connect | |
conn, err := net.Dial(proto, server) | |
if err != nil { | |
fmt.Fprintf(os.Stderr, "Dial error: %v\n", err) | |
} | |
defer conn.Close() | |
// send command | |
name := "girc" | |
room := "#Test" | |
fmt.Fprintf(conn, "USER %s 8 * :%s\r\n", name, name) | |
fmt.Fprintf(conn, "NICK %s\r\n", name) | |
fmt.Fprintf(conn, "JOIN %s\r\n", room) | |
// read message from irc server by conn | |
tp := textproto.NewReader(bufio.NewReader(conn)) | |
for { | |
line, err := tp.ReadLine() | |
if err != nil { | |
fmt.Println("ReadLine error: ", err) | |
break | |
} | |
fmt.Printf("%s\n", line) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment