http server

package main

import (
    "log"
    "net"
    "fmt"
    "bufio"
)

func main() {
    l, err := net.Listen("tcp", ":1993")
    if err != nil {log.Fatal(err)}
    for {
        conn, err := l.Accept()
        if err != nil {log.Fatal(err)}
        reader := bufio.NewReader(conn)
        go func() {
            for {
                line, _, _ := reader.ReadLine()
                fmt.Printf("%s\n", line)
                if len(line) == 0 {break}
            }
            conn.Write([]byte("HTTP/1.1 200 OK \r\n\r\n"))
            conn.Write([]byte(`hello world`))
            conn.Close()
        }()
    }
}

你可能感兴趣的:(http server)