Last active
October 2, 2019 02:42
-
-
Save wktk/dc63b2ba2dca2d8cb033f0b86df2fafd to your computer and use it in GitHub Desktop.
WHOIS Server 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" | |
"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