# Opening Sockets to TCP devices using scripting

**URL:** <https://forum.inductiveautomation.com/t/opening-sockets-to-tcp-devices-using-scripting/76860>\
**Category:** Ignition\
**Tags:** ignition81, scripting\
**Created:** [July 25, 2023, 1:03pm UTC](https://forum.inductiveautomation.com/t/opening-sockets-to-tcp-devices-using-scripting/76860 "2023-07-25T13:03:41Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 26, 2023, 3:19pm UTC](https://forum.inductiveautomation.com/t/opening-sockets-to-tcp-devices-using-scripting/76860/11 "2023-07-26T15:19:36Z")

</div>

Yes. It's unfortunate, but you're just setting yourself up for failure if you use `socket` directly.

Chat-GPT translated `java.net.Socket` equivalent of your snippet, that looks approximately correct:

```auto
# Jython Client using java.net.Socket

import java.net.Socket
import java.io.IOException

TCP_IP = '192.168.1.100'
TCP_PORT = 17001
CONNECTION_TIMEOUT = 5000 # The timeout is specified in milliseconds

try:
    s = Socket(TCP_IP, TCP_PORT)
    s.setSoTimeout(CONNECTION_TIMEOUT)

    out_stream = s.getOutputStream()
    message = 'this is a text message'
    out_stream.write(message.encode('utf-8'))

    s.close()

except IOException as e:
    print("Error:", e)
except Exception as e:
    print("Error:", e)

```

---

_[View the full topic](https://forum.inductiveautomation.com/t/opening-sockets-to-tcp-devices-using-scripting/76860)._
