Created
September 5, 2023 05:11
-
-
Save secondarykey/b10423481b26bf5d8ce8a7327753feef to your computer and use it in GitHub Desktop.
一般社団法人サイバー技術・インターネット自由研究会の電子公告のGo版
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" | |
"net" | |
"time" | |
"golang.org/x/text/encoding/japanese" | |
"golang.org/x/text/transform" | |
) | |
func main() { | |
addr := "koukoku.shadan.open.ad.jp:23" | |
conn, err := net.Dial("tcp", addr) | |
if err != nil { | |
return | |
} | |
defer conn.Close() | |
//ここをコメントアウトしたら全部読めます。 | |
conn.SetReadDeadline(time.Now().Add(20 * time.Second)) | |
reader := transform.NewReader(conn, japanese.ShiftJIS.NewDecoder()) | |
scanner := bufio.NewScanner(reader) | |
scanner.Split(bufio.ScanRunes) | |
for scanner.Scan() { | |
fmt.Print(scanner.Text()) | |
//ここを有効にすると全部読んだあとに自動で切断されます | |
//conn.SetReadDeadline(time.Now().Add(1 * time.Second)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment