Skip to content

Instantly share code, notes, and snippets.

@GoesToEleven
Created October 1, 2016 06:58
Show Gist options
  • Save GoesToEleven/58a37ad7ecc1dd5e8740a05b3c082d97 to your computer and use it in GitHub Desktop.
Save GoesToEleven/58a37ad7ecc1dd5e8740a05b3c082d97 to your computer and use it in GitHub Desktop.
package main
import (
"net"
"log"
"io"
"fmt"
)
func main() {
ln, err := net.Listen("tcp", ":9000")
if err != nil {
log.Fatalln("listen messed up", err.Error())
panic(err)
}
defer ln.Close()
for {
conn, err := ln.Accept()
if err != nil {
log.Fatalln("conn messed up", err.Error())
panic(err)
}
var bs = make([]byte, 1024)
n, err := conn.Read(bs)
if err != nil {
log.Fatalln("read messed up", err.Error())
panic(err)
}
m, err := conn.Write(bs)
if err != nil {
log.Fatalln("write messed up", err.Error())
panic(err)
}
io.WriteString(conn, fmt.Sprintln("Bytes read: ", n))
io.WriteString(conn, fmt.Sprintln("Bytes written: ", m))
conn.Close()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment