Add chat-tests
Planning to rewrite mini-chat from the ground up
This commit is contained in:
parent
e16bc31a11
commit
6a75e7cd41
|
@ -0,0 +1,3 @@
|
|||
module chat-tests
|
||||
|
||||
go 1.22.2
|
|
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue