Created
April 8, 2017 13:49
-
-
Save notchi590/d8d4fc594a2e873f3866d49468ee29dc to your computer and use it in GitHub Desktop.
extreme simple tcp server written in Golang
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 ( | |
"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