Gaurav_soni
Gaurav_soni

Reputation: 6114

twisted self.transport.write() - Python - Appended output

i am using Twisted python for sending reply to my client app (iPhone app). the reply does go to the client but i am getting a appended output string at the client end

This is the place where i am sending to my client -

for name in clientname:
                print "name in clientName array is"+name
                self.sendClientName(name)


def sendClientName(self , name):
    self.transport.write(name)
    print "client name sent to client app"

at the client end i am getting receiving the string which is concatenated -

ie: if i have the following in the clientname array - Jack,Rocky i receive the following string at the client end

"JackRocky" --- i want to save the names in the array so this is an issue.

Why is the server not sending the names one by one ?

Upvotes: 1

Views: 456

Answers (2)

Gaurav_soni
Gaurav_soni

Reputation: 6114

my code in the server script was wrong and not sending the appropriate message to the client application , just had to correct one loop now everything works fine.

Upvotes: 0

mensi
mensi

Reputation: 9826

With TCP connections there is no guarantee that two writes will translate to two reads at the other end, since the connection is considered to be one continues stream of bytes and buffering can happen anywhere. This means that you should send your array with some kind of element separator. If you have a library for serialization/deserialization for a common protocol on both client and server, it's usually easiest to just use this. A popular example is JSON (Python has a json module)

Upvotes: 2

Related Questions