Created
October 1, 2016 06:58
-
-
Save GoesToEleven/58a37ad7ecc1dd5e8740a05b3c082d97 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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