Send/receive message via TCP socket

Hello I'm attempting to send ASCII messages to a thermotron8800 controller via the script console calling the following gateway script. I keep getting a 'failed to connect connection refused error when testing the socket connection. I'm thinking I'll need to use a different socket for communication or is there a better way to send/receive status messages from Ignition to the controller?

def test_connection(ip, port):

import socket

try:
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((ip, port))
    status = "Connection successful"
except socket.error as e:
    status = "Failed to connect: {0}".format(e)
finally:
    sock.close()
    
return status

A 'connection refused' error indicates the error is entirely on the side of whatever you're trying to connect to. Either the controller itself or something else on the network in between is rejecting the attempt to connect from Ignition.

I would also generally recommend using Java's socket infrastructure over the Jython standard library.

1 Like