On 8 May 2007 06:59:26 -0700, [EMAIL PROTECTED] wrote:
>Hi,
>
>I'm trying to create a tcp/ip port listening socket server for various
>cellular devices that don't use the standard "\r\n" termination string
>at the end of their message.  Instead, they use "-ND-".  Do you know
>how I can setup such a server, preferably using either 'socket.py',
>'serversocket.py' or 'twisted.py'?

You can use the LineReceiver (or LineOnlyReceiver) from Twisted to do this
quite easily:

    from twisted.internet import reactor
    from twisted.internet.protocol import ServerFactory
    from twisted.protocols.basic import LineOnlyReceiver

    class CellProtocol(LineOnlyReceiver):
        delimiter = '-ND-'

    def lineReceived(self, line):
        print 'got a line'

    f = ServerFactory()
    f.protocol = CellProtocol
    reactor.listenTCP(12345, f)
    reactor.run()

Jean-Paul
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to