# Read data from TCP Printer

**URL:** <https://forum.inductiveautomation.com/t/read-data-from-tcp-printer/104583>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [April 2, 2025, 11:47am UTC](https://forum.inductiveautomation.com/t/read-data-from-tcp-printer/104583 "2025-04-02T11:47:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [April 2, 2025, 11:47am UTC](https://forum.inductiveautomation.com/t/read-data-from-tcp-printer/104583/1 "2025-04-02T11:47:56Z")

</div>

Hi,  
I am trying to read data from a TCP-connected printer. The connection has been verified using PowerShell, and the printer is reachable. However, when attempting to communicate via Python or from Ignition, the connection fails even after restarting the printer.

Here is the Python script I used:

```python
import socket

host = "<Printer_IP>"  
port = <Printer_Port>  

try:
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((host, port))
    print("Connection Successful!")

    command = "\n" # Sending a newline to test response
    s.sendall(command.encode())

    response = s.recv(4096).decode()
    print("Printer Response:", response)

    s.close()
except Exception as e:
    print("Connection Failed:", e)

```

Despite the TCP connection test passing in PowerShell, the script fails to establish communication. **Ignition also reports a connection failure.**

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [April 2, 2025, 11:48am UTC](https://forum.inductiveautomation.com/t/read-data-from-tcp-printer/104583/2 "2025-04-02T11:48:58Z")

</div>

What's the exact error and stack trace?

> [@Dharani\_T](#):
>
> The connection has been verified using PowerShell, and the printer is reachable.

Where are you executing this script in Ignition and what computer was this verified on with powershell?

---

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [April 2, 2025, 11:50am UTC](https://forum.inductiveautomation.com/t/read-data-from-tcp-printer/104583/3 "2025-04-02T11:50:35Z")

</div>

I have verified it in the gateway server:  
ComputerName : host  
RemoteAddress :host  
RemotePort : 3000  
InterfaceAlias : Ethernet  
SourceAddress : gateway ip  
TcpTestSucceeded : True

and am trying it from script console /gateway event  
Error:('Connection Failed:', error(107, 'Connection refused'))
