# Error Socket connection

**URL:** <https://forum.inductiveautomation.com/t/error-socket-connection/86873>\
**Category:** Ignition\
**Created:** [March 6, 2024, 7:44am UTC](https://forum.inductiveautomation.com/t/error-socket-connection/86873 "2024-03-06T07:44:07Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![Hayden\_Watson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/hayden_watson/32/48792_2.png) [@Hayden\_Watson](https://forum.inductiveautomation.com/u/Hayden_Watson)\
**Post date:** [March 8, 2024, 8:30am UTC](https://forum.inductiveautomation.com/t/error-socket-connection/86873/5 "2024-03-08T08:30:33Z")

</div>

As I said, you'll need to look into the java class docs. When I did it we had to convert our data into an array of bytes and send that down the socket, then read a response.

Using code like:

```auto
from java.net import Socket as javaSocket
import jarray
skt = javaSocket(ip_addr, port) #Java Socket declare
out_stream = skt.getOutputStream() # set socket send data stream

b_msg = jarray.array(to_convert_b_msg,'b') # Create Java array object for data transmission
		
out_stream.write(b_msg,0,len(b_msg)) # Write Data

```

This code won't work obviously but should be able to start to look up Java docs on how to implement for your case.

We did find that it massively reduced the memory leaking, so worth the time investment, but my java/Jython skills are pretty poor so maybe isn't super complciated to others.

> [@Using Java.net Socket](https://forum.inductiveautomation.com/t/using-java-net-socket/79962):
>
> Hey all, I'm trying to use the java sockets for some TCP devices. We're using the below code, our devices have a sort of API where they expect a byte array to be written. from java.net import Socket as javaSocket ...... skt = javaSocket(ip\_addr, port) #Java Socket declare, see imports at the top of module skt.setSoTimeout(CONNECTION\_TIMEOUT) #set timeout out\_stream = skt.getOutputStream() # set socket send data stream out\_stream.write(b\_msg) # write data out\_stream.flush() # flush data do…

This is the thread people helped me out on, though took some extra time to figure out how to get it working after

---

_[View the full topic](https://forum.inductiveautomation.com/t/error-socket-connection/86873)._
