Sandbox

From NYC Resistor Wiki
Jump to: navigation, search

Test Edit

[ifconfig.io]

package main

import (
        "net"
        "log"
        "bufio"
)
func tcpDoer(conn net.Conn, queue chan *Letter) {
        //Welcome the Person
        _, err := conn.Write([]byte("Welcome\n"))
        checkErr("Unable to respond:", err)

        // read data from the client
        data,_,err := bufio.NewReader(conn).ReadLine()
        line := string(data)

        //Do something the blocks, who cares the other connections won't notice

        _, err = conn.Write(response)
        checkErr("Unable to respond:", err)
       
        conn.Close()
}

func tcpWatcher(queue chan *Letter) {
        server, err := net.Listen("tcp", LISTENADDRESS)
        checkErr("Unable to bind:", err)
        defer server.Close()

        for {
                conn, err := server.Accept()
                checkErr("Problem accepting:", err)
                go tcpDoer(conn, queue)
        }
}

func main() {
        queue := make(chan *Letter, 100)
        go tcpWatcher(queue)
        
        select {} // Our main function is boring just block.
}


test

some junk down here to denote end