Skip to content

Instantly share code, notes, and snippets.

@s-panferov
Created January 14, 2014 18:41
Show Gist options
  • Save s-panferov/8423402 to your computer and use it in GitHub Desktop.
Save s-panferov/8423402 to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"fmt"
"net"
)
func handleConnection(conn net.Conn) {
fmt.Println(conn)
reader := bufio.NewReader(conn)
for {
line, err := reader.ReadBytes('\n')
if err != nil {
fmt.Println("Connection closed")
break
}
conn.Write(line)
}
defer conn.Close()
}
func main() {
ln, err := net.Listen("tcp", "0.0.0.0:8000")
if err != nil {
panic(err)
}
fmt.Println("Start server...")
for {
conn, err := ln.Accept()
if err != nil {
fmt.Println("Cannot process connection")
}
fmt.Println("Goto handle connection")
go handleConnection(conn)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment