Skip to content

Instantly share code, notes, and snippets.

@notchi590
Created April 8, 2017 13:49
Show Gist options
  • Save notchi590/d8d4fc594a2e873f3866d49468ee29dc to your computer and use it in GitHub Desktop.
Save notchi590/d8d4fc594a2e873f3866d49468ee29dc to your computer and use it in GitHub Desktop.
extreme simple tcp server written in Golang
package main
import (
"bufio"
"fmt"
"log"
"net"
)
func main() {
addr := "127.0.0.1:8080"
ln, err := net.Listen("tcp", addr)
if err != nil {
log.Fatal(err)
}
conn, _ := ln.Accept()
for {
message, _ := bufio.NewReader(conn).ReadString('\n')
fmt.Print("Message Received:", message)
conn.Write([]byte(message + "\n"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment