Add chat-tests

Planning to rewrite mini-chat from the ground up
This commit is contained in:
raul 2024-04-21 19:45:32 +02:00
parent e16bc31a11
commit 6a75e7cd41
2 changed files with 36 additions and 0 deletions

3
chat-tests/go.mod Normal file
View File

@ -0,0 +1,3 @@
module chat-tests
go 1.22.2

33
chat-tests/main.go Normal file
View File

@ -0,0 +1,33 @@
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)
}
}