more
This commit is contained in:
parent
fee2134652
commit
1c0a6d298f
30
xx-tcp-client.go
Normal file
30
xx-tcp-client.go
Normal file
@ -0,0 +1,30 @@
|
||||
package main
|
||||
|
||||
import ("fmt"; "net")
|
||||
|
||||
func client() {
|
||||
|
||||
}
|
||||
|
||||
func main() {
|
||||
c, err := net.Dial("tcp", "127.0.0.1:5000")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
msg := "Hello World"
|
||||
fmt.Println("Sending: ", msg)
|
||||
_, err = c.Write([]byte(msg))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
buf := make([]byte, 1024)
|
||||
_, err = c.Read(buf)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
fmt.Println("Received:", string(buf))
|
||||
c.Close()
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user