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 gchat | |
import "log" | |
import "net" | |
import "bufio" | |
import "fmt" | |
func Serve() { | |
fmt.Println("Start server on port 2000") | |
l, err := net.Listen("tcp", ":2000") | |
if err != nil { | |
log.Fatal(err) | |
} | |
for { | |
conn, err := l.Accept() | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println("Accepting conn") | |
go handleConn(conn) | |
} | |
} | |
func handleConn(c net.Conn) { | |
b := bufio.NewReader(c) | |
str, err := b.ReadString('\n') | |
fmt.Println(err) | |
for err != nil { | |
fmt.Println(err) | |
str, err = b.ReadString('\n') | |
} | |
fmt.Println(err) | |
fmt.Println("Closing") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment