add readout, remove localhost

This commit is contained in:
Evan Burkey 2022-11-07 10:30:51 -08:00
parent 45ed809b19
commit 4e9dffe5ad
1 changed files with 3 additions and 3 deletions

View File

@ -7,20 +7,19 @@ import (
) )
const ( const (
connHost = "localhost"
connPort = "3030" connPort = "3030"
connType = "tcp" connType = "tcp"
) )
func main() { func main() {
l, err := net.Listen(connType, connHost+":"+connPort) l, err := net.Listen(connType, ":"+connPort)
if err != nil { if err != nil {
fmt.Printf("net.Listen fail: %v\n", err) fmt.Printf("net.Listen fail: %v\n", err)
os.Exit(1) os.Exit(1)
} }
defer l.Close() defer l.Close()
fmt.Println(fmt.Sprintf("Listening on %s:%s", connHost, connPort)) fmt.Println(fmt.Sprintf("Listening on port %s", connPort))
for { for {
conn, err := l.Accept() conn, err := l.Accept()
@ -34,6 +33,7 @@ func main() {
func handleRequest(conn net.Conn) { func handleRequest(conn net.Conn) {
buf := make([]byte, 1024) buf := make([]byte, 1024)
_, err := conn.Read(buf) _, err := conn.Read(buf)
fmt.Printf("read in %s.\nSending it back\n", string(buf))
if err != nil { if err != nil {
fmt.Printf("Error reading: %v\n", err) fmt.Printf("Error reading: %v\n", err)
} }