E
E
Evgeny Glebov2019-04-29 17:01:16
go
Evgeny Glebov, 2019-04-29 17:01:16

Why doesn't Golang return an error when writing to net.Conn when the internet is down?

Hello. Here is part of the client code:

func (e *exchanger) trySendByTCP(data []byte) (done bool) {
  if e.tcpConnection == nil {
    return false
  }
  _, err := e.tcpConnection.Write(data)
  if err != nil {
    utils.LogE("Write to TCP error.", err)
  }
  return err == nil
}

I run on a device that is connected to the server via Wifi.
The problem is that if I turn off the Wifi hotspot, the code runs as if there is internet and everything is sent, although logically it should return err != nil.
What could be the problem? How do I send a confirmation?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question