From c5fc33b7517c379f0318d5b0e62183cc7c298166 Mon Sep 17 00:00:00 2001 From: Meutel Date: Sun, 9 Jul 2017 15:15:38 +0200 Subject: [PATCH] TCP echo server --- .gitignore | 1 + echoserver/main.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 echoserver/main.go diff --git a/.gitignore b/.gitignore index ac7b209..977e020 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,4 @@ statecsv2json/statecsv2json converter-main/converter-main tcpclient/tcpclient tcpserver/tcpserver +echoserver/echoserver diff --git a/echoserver/main.go b/echoserver/main.go new file mode 100644 index 0000000..5a3bc62 --- /dev/null +++ b/echoserver/main.go @@ -0,0 +1,23 @@ +package main + +import ( + "io" + "net" +) + +func main() { + ln, err := net.Listen("tcp", ":9000") + if err != nil { + panic(err) + } + defer ln.Close() + + for { + conn, err := ln.Accept() + if err != nil { + panic(err) + } + io.Copy(conn, conn) + conn.Close() + } +}