Skip to content

Instantly share code, notes, and snippets.

@wktk
Last active October 2, 2019 02:42
Show Gist options
  • Save wktk/dc63b2ba2dca2d8cb033f0b86df2fafd to your computer and use it in GitHub Desktop.
Save wktk/dc63b2ba2dca2d8cb033f0b86df2fafd to your computer and use it in GitHub Desktop.
WHOIS Server in Golang
package main
import (
"bufio"
"log"
"net"
"strings"
)
func main() {
ln, err := net.Listen("tcp", ":43")
if err != nil {
log.Fatal(err)
}
for {
conn, err := ln.Accept()
if err != nil {
log.Fatal(err)
}
go handleConnection(conn)
}
}
func handleConnection(conn net.Conn) {
message, err := bufio.NewReader(conn).ReadString('\n')
if err != nil {
log.Fatal(err)
}
log.Print("Message Received:", string(message))
newmessage := strings.ToUpper(message)
conn.Write([]byte(newmessage))
defer conn.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment