Skip to content

Instantly share code, notes, and snippets.

@gomasy
Created September 7, 2023 15:49
Show Gist options
  • Save gomasy/a0f0ac0ffc682c84de268707fe858311 to your computer and use it in GitHub Desktop.
Save gomasy/a0f0ac0ffc682c84de268707fe858311 to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"fmt"
"log"
"net"
"strconv"
"golang.org/x/text/transform"
"golang.org/x/text/encoding/japanese"
)
func Connect(host string, port int) net.Conn {
conn, err := net.Dial("tcp", host + ":" + strconv.Itoa(port))
if err != nil {
log.Fatal(err)
}
log.Print("Connected to " + host + " port " + strconv.Itoa(port))
return conn
}
func main() {
conn := Connect("koukoku.shadan.open.ad.jp", 23)
defer conn.Close()
fmt.Fprintln(conn, "nobody")
scanner := bufio.NewScanner(conn)
for scanner.Scan() {
str, _, err := transform.String(japanese.ShiftJIS.NewDecoder(), scanner.Text())
if err != nil {
log.Fatal(err)
}
fmt.Println(str)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment