Template protocol with xml data. #1456
-
Im trying to interface to a gps signal simulator (spirent) and not sure of the best way to do this. Commands are ascii, with the response being xml data. It is a send / receive protocol so I was looking at the template protocol, but the xml responses was throwing me off. In the basic example I would transmit ascii Response data is usually in the data attribute xml field. A python example of the protocol s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((self.TCP_IP, self.TCP_PORT))
s.send("NULL") Server spirent return_msg = b'<msg>\n\t<status> 7 </status>\n</msg>\n\r'
import socket
HOST = '127.0.0.1' # Standard loopback interface address (localhost)
PORT = 65432 # Port to listen on (non-privileged ports are > 1023)
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((HOST, PORT))
s.listen()
conn, addr = s.accept()
with conn:
print('Connected by', addr)
while True:
data = conn.recv(1024)
if not data:
continue
print(data)
conn.sendall(return_msg)
~ |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I tried chaining protocls
However it appears using TemplateProtocol vs the TEMPLATE command causes the template magic to not occur.
|
Beta Was this translation helpful? Give feedback.
-
Ok i got something that worked. I ended up creating a second protocol to strip off the XML flags.
Then I chained this together with the template protocol.
Two things to note.
|
Beta Was this translation helpful? Give feedback.
Ok i got something that worked.
I ended up creating a second protocol to strip off the XML flags.