func main() {
server := "localhost:8989"
tcpAddr, err := net.ResolveTCPAddr("tcp4", server)
if err != nil {
fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error())
os.Exit(1)
}
conn, err := net.DialTCP("tcp", nil, tcpAddr)
if err != nil {
fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error())
os.Exit(1)
}
fmt.Println("connect success")
for i := 0; i < 10; i++ {
j, err := conn.Write([]byte("hello"))
if err != nil {
fmt.Printf("conn.Write err: %v\n", err)
continue
}
fmt.Printf("time[%v] conn.Write len: %v\n", i+1, j)
time.Sleep(5 * time.Second)
}
}
Я отправляю 10 сообщений на tcp сервер с демо. И я получаю это:
connect success
time[1] conn.Write len: 5
time[2] conn.Write len: 5
time[3] conn.Write len: 5
conn.Write err: write tcp 127.0.0.1:52462->127.0.0.1:8989: wsasend: An established connection was aborted by the software in your host machine.
conn.Write err: write tcp 127.0.0.1:52462->127.0.0.1:8989: wsasend: An established connection was aborted by the software in your host machine.
conn.Write err: write tcp 127.0.0.1:52462->127.0.0.1:8989: wsasend: An established connection was aborted by the software in your host machine.
conn.Write err: write tcp 127.0.0.1:52462->127.0.0.1:8989: wsasend: An established connection was aborted by the software in your host machine.
conn.Write err: write tcp 127.0.0.1:52462->127.0.0.1:8989: wsasend: An established connection was aborted by the software in your host machine.
conn.Write err: write tcp 127.0.0.1:52462->127.0.0.1:8989: wsasend: An established connection was aborted by the software in your host machine.
conn.Write err: write tcp 127.0.0.1:52462->127.0.0.1:8989: wsasend: An established connection was aborted by the software in your host machine.
Я закрыл сервер перед третьим сообщением. Но третье сообщение успешно опубликовано. conn.Write err
получить ноль. Я не могу понять Кто может сказать мне, почему? Спасибо.