-
-
Save afrolovskiy/06b134b4a0213c945f73 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 ( | |
"net" | |
"os" | |
) | |
func main() { | |
strEcho := "Halo" | |
servAddr := "localhost:6666" | |
tcpAddr, err := net.ResolveTCPAddr("tcp", servAddr) | |
if err != nil { | |
println("ResolveTCPAddr failed:", err.Error()) | |
os.Exit(1) | |
} | |
conn, err := net.DialTCP("tcp", nil, tcpAddr) | |
if err != nil { | |
println("Dial failed:", err.Error()) | |
os.Exit(1) | |
} | |
_, err = conn.Write([]byte(strEcho)) | |
if err != nil { | |
println("Write to server failed:", err.Error()) | |
os.Exit(1) | |
} | |
println("write to server = ", strEcho) | |
reply := make([]byte, 1024) | |
_, err = conn.Read(reply) | |
if err != nil { | |
println("Write to server failed:", err.Error()) | |
os.Exit(1) | |
} | |
println("reply from server=", string(reply)) | |
conn.Close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment