0

I am trying to build an ios application with python and monngodb at backend. I am using twisted library to create sockets connection. The server seems to recieve the data when it consists only the ascii characters but when string contains non-ASCII characters such as 'å' 'ö' 'ä', nothing happens in the server. The dataRecieved method is not triggered at all.

this is my testing code:

from twisted.internet.protocol import Factory, Protocol
from twisted.internet import reactor



class Test(Protocol):
    def connectionMade(self):
        self.factory.clients.append(self)
        print "clients are ", self.factory.clients

    def connectionLost(self, reason):
        self.factory.clients.remove(self)   
        print "clients are removed"

    def dataReceived(self, data):
        print data

factory = Factory() 
factory.clients = []

factory.protocol = Test 
reactor.listenTCP(80, factory) 
print "server started" 
reactor.run()
  • It works fine for me. And there's no reason I'd expect it not to. Protocol's don't care about ASCII. They work with bytes, not text. Perhaps the problem is actually on the client you use to send these bytes. Maybe it can't actually send them. – Jean-Paul Calderone Nov 20 '13 at 21:08
  • thanks.. But I 'NSLog'ed the response in the output stream, and i can see the text containing characters like "å,ö". and besides i tried to connect directly from shell using 'telnet localhost 80' in that case when i try these characters it gets in as '%c' which is basically ascii. i will look more into the NSStream library, thanks again – user2756092 Nov 21 '13 at 16:09
  • Can you simply strip the non-Ascii characters? http://stackoverflow.com/questions/1342000/how-to-make-the-python-interpreter-correctly-handle-non-ascii-characters-in-stri – duhaime Nov 22 '13 at 00:12

0 Answers0