github.com/dara-project/godist@v0.0.0-20200823115410-e0c80c8f0c78/dara_tests/server.go (about) 1 package main 2 3 import "net" 4 import "fmt" 5 import "bufio" 6 7 func main() { 8 9 fmt.Println("Launching server...") 10 11 // listen on all interfaces 12 ln, err := net.Listen("tcp", ":18081") 13 14 if err != nil { 15 fmt.Println(err) 16 } 17 fmt.Println("Listening now...") 18 // accept connection on port 19 conn, err := ln.Accept() 20 fmt.Println("Acception connection") 21 // run loop forever (or until ctrl-c) 22 for { 23 // will listen for message to process ending in newline (\n) 24 message, _ := bufio.NewReader(conn).ReadString('\n') 25 // output message received 26 // sample process for string received 27 // send new string back to client 28 conn.Write([]byte(message + "\n")) 29 } 30 }