# Socket Server failing on receive

**URL:** <https://forum.inductiveautomation.com/t/socket-server-failing-on-receive/10234>\
**Category:** Ignition\
**Created:** [July 16, 2015, 5:40pm UTC](https://forum.inductiveautomation.com/t/socket-server-failing-on-receive/10234 "2015-07-16T17:40:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![d3h637](https://avatars.discourse-cdn.com/v4/letter/d/13edae/32.png) [@d3h637](https://forum.inductiveautomation.com/u/d3h637)\
**Post date:** [July 16, 2015, 5:40pm UTC](https://forum.inductiveautomation.com/t/socket-server-failing-on-receive/10234/1 "2015-07-16T17:40:18Z")

</div>

I have a devices that I need to receive data from via TCP/IP packets. The catch is that ignition must act as the server. I am working on a simple script to read the ASCII data stream and bring the data into Ignition. Whenever I call the socket.recv function from my script, it fails with an error referencing a Java library. Any ideas? Below is the script I’ve written, and the error message is below. I have run the script in asynchronous mode an non asynchronous mode and the error is the same. The recv function fails before any data is sent to the server machine.

import socket  
import sys  
def TCPThread():  
import socket

```
SocketServer = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
SocketServer.bind((socket.gethostbyname(socket.gethostname()),5287))
SocketServer.listen(2)
print 'listening'
print SocketServer.getsockname()
Conn, addr = SocketServer.accept()
print 'Connected With :' + addr[0] + ':' + str(addr[1])
x = 0
while x < 4:
	data = SocketServer.recv(16)	
	print x
	x=x+1
SocketServer.close()

```

system.util.invokeAsynchronous(TCPThread)

Traceback (most recent call last): File “event:actionPerformed”, line 15, in TCPThread File “C:\Users\User\AppData\LocalLow\Sun\Java\Deployment\cache\FPMI\script\_lib2\Lib\socket.py”, line 1185, in recv if self.sock\_impl.jchannel.isConnectionPending(): File “C:\Users\User\AppData\LocalLow\Sun\Java\Deployment\cache\FPMI\script\_lib2\Lib\socket.py”, line 1185, in recv if self.sock\_impl.jchannel.isConnectionPending():AttributeError: ‘sun.nio.ch.ServerSocketChannelImpl’ object has no attribute ‘isConnectionPending’

Ignition v7.6.7 (b2014082615)  
Java: Oracle Corporation 1.7.0\_75

---

<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:** [July 16, 2015, 5:53pm UTC](https://forum.inductiveautomation.com/t/socket-server-failing-on-receive/10234/2 "2015-07-16T17:53:27Z")

</div>

I’m not really familiar with the underlying Jython implementation, so there could be a bug there, but you’re probably supposed to be calling recv() on the conn object you got back from accept(), not the listening socket.

---

<div class="post-metadata">

**Author:** ![d3h637](https://avatars.discourse-cdn.com/v4/letter/d/13edae/32.png) [@d3h637](https://forum.inductiveautomation.com/u/d3h637)\
**Post date:** [July 20, 2015, 7:30pm UTC](https://forum.inductiveautomation.com/t/socket-server-failing-on-receive/10234/3 "2015-07-20T19:30:42Z")

</div>

Thanks for the reply. That fixed the problem.

Changing the line:  
data = SocketServer.recv(16)

to:  
data = Conn.recv(16)

Allowed the script to run correctly
