From NYC Resistor Wiki
Jump to navigation Jump to search

Test Edit


package main

import (
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)

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.


some junk down here to denote end