2

I am trying to communicate with a device (connected using ethernet) using TCP/IP connection. When a connection request is sent, I am getting an error:

dial tcp 192.168.137.10:502: connectex: A connection attempt failed because
the connected party did not properly respond after a period of time,
or established connection failed because connected host has failed to respond

But if I am connecting to the simulator (which will act as device), it is getting connected and sending me response.

I am using GO for coding. This is my code to connect to device

conn, err := net.Dial("tcp", "192.168.137.10:502")
if err != nil {
  return nil, err
} else {
  return conn, nil
}

Hardware Info:

  • Windows 10, 64 bit machine
  • PLC device connected over TCP/IP
SiHa
  • 7,830
  • 13
  • 34
  • 43
Bhavana
  • 1,014
  • 4
  • 17
  • 26
  • 1
    Most probably Go is out of question here, and the H/W device is at fault. Verification of such cases is straightforward: you need to exclude the possibility Go is at fault by attempting the same connection by different means. I'd try `telnet 192.168.137.10 502`. Here's [how to do it](https://www.google.com/search?q=windows+10+telnet). If you will find out `telnet` works, and your Go program still does not, *that* would be an interesting situation, so then please come back with a refined question. – kostix Mar 20 '18 at 13:18

1 Answers1

1

I suspect that there is a problem with the server and not your client code. The fact that you aren't just getting a "connection refused" error tells me that the remote port is probably open. Chances are that the server is not performing an accept() on the incoming connection within a reasonable time.

Things that might cause this

  • Maximum number of connection configured on the server has been exceeded or the service is too busy.
  • Server has crashed
  • Funny firewall or another routing issue between you and the server. Some deep packet inspection firewalls sometimes cause these types of issues.

I suggest you try and do troubleshooting on the server side.

Stephan
  • 69
  • 5