Created
January 14, 2014 18:41
-
-
Save s-panferov/8423402 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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