Created
September 7, 2023 15:49
-
-
Save gomasy/a0f0ac0ffc682c84de268707fe858311 to your computer and use it in GitHub Desktop.
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" | |
"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