tags:

views:

35

answers:

2

Hello, i need to connect to a blocking service using tcp ports (if someone here knows about it, it is a motorola digital wirelink protocol service) , i need a good starting point example, ideally in perl, python or php which are the languages i know better.

So far i have tried this basic example with no luck.

import socket import sys

HOST, PORT = "172.16.10.5", 15142 data = " ".join(sys.argv[1:])

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((HOST, PORT)) print "connected"

sock.send(data + "\n") print "data sent"

received = sock.recv(1024) print "data received" sock.close()

print "Sent: %s" % data print "Received: %s" % received

the script just hangs forever after sock.send do anyone of you know of a good example? regards

A: 

I don't know about this specific protocol, but instead of managing sockets yourself, I would have to recommend the Twisted framework for networking in Python.

Twisted is an event-driven networking engine written in Python and licensed under the MIT license.

Jesse Dhillon
i have looked at the twisted framework, but i think (by reading the docs) it is for asyncronous non-blocking sockets, i need it syncronous blocking.
+1  A: 

You probably need \r\n instead of \n. If you don't terminate properly, a response won't be sent.

Mark Tolonen
i change it to "\r\n", but same result... :-(
If it is hanging, the data being sent is not correct. It is waiting for a complete command. Check the protocol and make sure you are following it exactly.
Mark Tolonen