Hello.
(( sorry, not clear why the code below is formatting like that ))
I am unclear on the correct way for my TCP socket server to behave to satisfy what the Mango client is looking for. In the help box for the TCPIP data source, there is this statement: "The timeout determines when to abandon listening for a completed response, a timeout of 0 means no timeout. When using a timeout if a message is received with no EOF (end of file) or connection close, then the message will not be processed until after the timeout has been reached." I see this behavior exactly. Looking at Mango's tcpipIO log file, I see the "I" response occurring exactly after the "O" command string by the specified timeout value in the TCPIP data source.
How would the TCPIP server send an EOF back to Mango? I have tried closing the connection for each poll from Mango, but that results in lost messages (every other one). The little test loop I am testing Mango with is as shown below. Note that using a timeout of zero seems to work fine and causes no problems in the test configuration, but I would like to understand how to use this data source as intended by Mango.
Any help would be appreciated! Thank you.
import socket
import sys
import time
HOST = '10.90.2.133'
PORT = 7001
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print('# Socket created')
--Create socket on port
try:
s.bind((HOST, PORT))
except socket.error as msg:
print('# Bind failed. ')
sys.exit()
print('# Socket bind complete')
-- Start listening on socket
s.listen(10)
print('# Socket now listening')
-- Wait for client
conn, addr = s.accept()
print('# Connected to ' + addr[0] + ':' + str(addr[1]) + "@" + time.strftime("%H:%M:%S") )
value = 123
-- Receive data from client
try:
while True:
# Wait for client
data = conn.recv(1024)
line = data.decode('UTF-8') # convert to string (Python 3 only)
line = line.replace("\n","") # remove newline character
if len(line) > 1 :
print " INPUT == " + line
if line == "BZNREAD" :
value = value + 1
data = str(value) + "\n"
print " RSP -> " + data + "\n"
conn.send(data.encode()) # send data to the client
except socket.error as msg:
print "Closing socket\n"
s.close()