Created
April 5, 2019 17:27
-
-
Save ddebroy/3961d5ecb306fe27f716da304f9c2e83 to your computer and use it in GitHub Desktop.
socket client for Windows
This file contains hidden or 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 ( | |
| "io" | |
| "log" | |
| "net" | |
| // "time" | |
| ) | |
| func reader(r io.Reader) { | |
| buf := make([]byte, 1024) | |
| for { | |
| n, err := r.Read(buf[:]) | |
| if err != nil { | |
| return | |
| } | |
| println("Client got:", string(buf[0:n])) | |
| } | |
| } | |
| func main() { | |
| c, err := net.Dial("unix", "c:\\var\\lib\\kubelet\\plugins\\pd.csi.storage.gke.io\\csi.sock") | |
| if err != nil { | |
| log.Fatal("Dial error", err) | |
| } | |
| println("dialed successfully") | |
| defer c.Close() | |
| go reader(c) | |
| for { | |
| msg := "hi" | |
| _, err := c.Write([]byte(msg)) | |
| if err != nil { | |
| log.Fatal("Write error:", err) | |
| break | |
| } | |
| println("Client sent:", msg) | |
| time.Sleep(1e9) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment