Last active
August 29, 2015 14:15
-
-
Save ajackson/ea4f03785f3f820c8eec 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
$ go run src/github.com/ajackson/misc/tcp_writer.go | |
Failed to dial dial tcp 127.0.0.1:12345: connection refused | |
Failed to dial dial tcp 127.0.0.1:12345: connection refused | |
Failed to dial dial tcp 127.0.0.1:12345: connection refused | |
Failed to dial dial tcp 127.0.0.1:12345: connection refused | |
Failed to dial dial tcp 127.0.0.1:12345: connection refused | |
Failed to dial dial tcp 127.0.0.1:12345: connection refused | |
Failed to dial dial tcp 127.0.0.1:12345: connection refused | |
Wrote data successfully | |
Wrote data successfully | |
Wrote data successfully | |
Wrote data successfully | |
Wrote data successfully | |
Wrote data successfully | |
Wrote data successfully | |
Wrote data successfully | |
Wrote data successfully | |
Wrote data successfully | |
Wrote data successfully | |
Failed to write data write tcp 127.0.0.1:12345: broken pipe | |
Failed to dial dial tcp 127.0.0.1:12345: connection refused | |
Failed to dial dial tcp 127.0.0.1:12345: connection refused | |
Failed to dial dial tcp 127.0.0.1:12345: connection refused | |
Failed to dial dial tcp 127.0.0.1:12345: connection refused |
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
$ nc -l 12345 | |
Some data for you | |
Some data for you | |
Some data for you | |
Some data for you | |
Some data for you | |
Some data for you | |
Some data for you | |
Some data for you | |
Some data for you | |
Some data for you | |
Some data for you | |
^C | |
$ |
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" | |
func main() { | |
data := []byte("Some data for you\n") | |
for { | |
conn, err := net.Dial("tcp", "localhost:12345") | |
if err != nil { | |
println("Failed to dial", err.Error()) | |
continue | |
} | |
for { | |
_, err = conn.Write(data) | |
println("Wrote data successfully") | |
if err != nil { | |
println("Failed to write data", err.Error()) | |
break | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment