Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ControlConn simple tcp server for commands
- func ControlConn() {
- ln, err := net.Listen("tcp", ":"+TCPPort)
- if err != nil {
- log.Println("[control] error listening:", err.Error())
- }
- log.Printf("[control] listening to port %s for connections...", TCPPort)
- for {
- conn, err := ln.Accept()
- bot := NewBot()
- bot.inconn = conn
- if err != nil {
- fmt.Println("[control] Error accepting: ", err.Error())
- }
- handleRequest(conn, bot)
- }
- }
- func handleRequest(conn net.Conn, bot *Bot) {
- defer conn.Close()
- reader := bufio.NewReader(conn)
- tp := textproto.NewReader(reader)
- for {
- line, err := tp.ReadLine()
- if err != nil {
- fmt.Println("[control] read error:", err)
- conn.Close()
- return
- }
- log.Println("[control] " + line)
- handleMessage(line, bot)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment