golang-exercises/chat-tests/main.go

34 lines
464 B
Go
Raw Normal View History

package main
import (
"fmt"
"log"
"net"
)
const (
port string = "1302"
)
func main() {
ln, err := net.Listen("tcp", ":"+port)
checkErr(err)
fmt.Printf("Listening on port %v...\n", port)
for {
conn, err := ln.Accept()
checkErr(err)
go handleFunc(conn)
}
}
func handleFunc(conn net.Conn) {
fmt.Println("Received connection")
fmt.Fprintln(conn, "Hello buddy!")
}
func checkErr(err error) {
if err != nil {
log.Fatalf("Error: %v\n", err)
}
}