Socket Server failing on receive

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

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.

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