asdf
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
module main
|
||||
|
||||
go 1.25.5
|
||||
@@ -0,0 +1,45 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func echo(c net.Conn, shout string, t time.Duration) {
|
||||
fmt.Fprintln(c, "\t", strings.ToUpper(shout))
|
||||
time.Sleep(t)
|
||||
fmt.Fprintln(c, "\t", shout)
|
||||
time.Sleep(t)
|
||||
fmt.Fprintln(c, "\t", strings.ToLower(shout))
|
||||
}
|
||||
|
||||
func handleConn(conn net.Conn) {
|
||||
defer fmt.Println("CLosed Connection")
|
||||
defer conn.Close()
|
||||
|
||||
fmt.Println("Accepted connection")
|
||||
input := bufio.NewScanner(conn)
|
||||
for input.Scan() {
|
||||
go echo(conn, input.Text(), 1*time.Second)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func main() {
|
||||
listener, err := net.Listen("tcp", ":9090")
|
||||
if err != nil {
|
||||
log.Fatalf("Error %v", err)
|
||||
}
|
||||
|
||||
for {
|
||||
conn, err := listener.Accept()
|
||||
if err != nil {
|
||||
log.Fatalf("Error in Accept %s", err)
|
||||
}
|
||||
go handleConn(conn)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user