Re: Python recv loop

2013-02-11 Thread MRAB
On 2013-02-12 02:20, Chris Angelico wrote: On Tue, Feb 12, 2013 at 12:41 PM, Ihsan Junaidi Ibrahim wrote: On Feb 11, 2013, at 11:24 PM, Chris Angelico wrote: On Tue, Feb 12, 2013 at 2:11 AM, MRAB wrote: I probably wouldn't make it fixed length. I'd have the length in decimal followed by,

Re: Python recv loop

2013-02-11 Thread Roy Smith
In article , Ihsan Junaidi Ibrahim wrote: > I'm running JSON for my application messaging protocol but with JSON and > python default unordered dict, > there's no guarantee if I put in the length key in the JSON message, it will > be placed on the first bytes hence > why it was designed for a

Re: Python recv loop

2013-02-11 Thread Chris Angelico
On Tue, Feb 12, 2013 at 12:41 PM, Ihsan Junaidi Ibrahim wrote: > > On Feb 11, 2013, at 11:24 PM, Chris Angelico wrote: > >> On Tue, Feb 12, 2013 at 2:11 AM, MRAB wrote: >>> I probably wouldn't make it fixed length. I'd have the length in >>> decimal followed by, say, "\n". >> >> Or even "followe

Re: Python recv loop

2013-02-11 Thread Ihsan Junaidi Ibrahim
On Feb 11, 2013, at 11:24 PM, Chris Angelico wrote: > On Tue, Feb 12, 2013 at 2:11 AM, MRAB wrote: >> I probably wouldn't make it fixed length. I'd have the length in >> decimal followed by, say, "\n". > > Or even "followed by any non-digit". Chances are your JSON data begins > with a non-digi

Re: Python recv loop

2013-02-11 Thread Dave Angel
On 02/11/2013 10:02 AM, Ihsan Junaidi Ibrahim wrote: print 'message length is {0}'.format(nbuf) while True: buf = sock.recv(nbuf) if not buf: break This loop doesn't terminate till buf is zero length, which it will be eventually. At that point,

Re: Python recv loop

2013-02-11 Thread Chris Angelico
On Tue, Feb 12, 2013 at 2:11 AM, MRAB wrote: > I probably wouldn't make it fixed length. I'd have the length in > decimal followed by, say, "\n". Or even "followed by any non-digit". Chances are your JSON data begins with a non-digit, so you'd just have to insert a space in the event that you're

Re: Python recv loop

2013-02-11 Thread MRAB
On 2013-02-11 14:56, Ihsan Junaidi Ibrahim wrote: Hi Roy, On Feb 11, 2013, at 10:24 AM, Roy Smith wrote: Is this server that you're talking to something that you have control over, i.e. are you stuck with this protocol? Given a choice, I'd go with something like JSON, for which pre-existing

Re: Python recv loop

2013-02-11 Thread Ihsan Junaidi Ibrahim
Hi MRAB, My code now works thanks to your advice. {"msgver": "1.0", "msgid": "200", "subcode": "100", "appver": "1.0", "appid": "1.0", "data": {"1": "igb0", "2": "igb1", "ifcnt": "2"}} connected to misty:8080 sending data 138 bytes sent: 0x86{"msgver": "1.0", "msgid": "200", "subcode": "100", "

Re: Python recv loop

2013-02-11 Thread Ihsan Junaidi Ibrahim
Hi Dave, On Feb 11, 2013, at 9:22 AM, Dave Angel wrote: > Exactly how are you sending "hexadecimal" ? If that 0xad (which is only one > byte, what about the other 3 ?) is intended to be a C description, then it's > certainly not hex, it's binary. And probably little-endian, to boot. That's

Re: Python recv loop

2013-02-11 Thread Ihsan Junaidi Ibrahim
Hi Roy, On Feb 11, 2013, at 10:24 AM, Roy Smith wrote: > > Is this server that you're talking to something that you have control > over, i.e. are you stuck with this protocol? Given a choice, I'd go > with something like JSON, for which pre-existing libraries for every > language under the s

Re: Python recv loop

2013-02-10 Thread Roy Smith
In article , Ihsan Junaidi Ibrahim wrote: > I'm implementing a python client connecting to a C-backend server and am > currently stuck to as to how to proceed with receiving variable-length byte > stream coming in from the server. > > I have coded the first 4 bytes (in hexadecimal) of message

Re: Python recv loop

2013-02-10 Thread MRAB
On 2013-02-11 00:48, Ihsan Junaidi Ibrahim wrote: Hi, I'm implementing a python client connecting to a C-backend server and am currently stuck to as to how to proceed with receiving variable-length byte stream coming in from the server. I have coded the first 4 bytes (in hexadecimal) of messa

Re: Python recv loop

2013-02-10 Thread Dave Angel
On 02/10/2013 07:48 PM, Ihsan Junaidi Ibrahim wrote: Hi, I'm implementing a python client connecting to a C-backend server and am currently stuck to as to how to proceed with receiving variable-length byte stream coming in from the server. I have coded the first 4 bytes (in hexadecimal) of me

Python recv loop

2013-02-10 Thread Ihsan Junaidi Ibrahim
Hi, I'm implementing a python client connecting to a C-backend server and am currently stuck to as to how to proceed with receiving variable-length byte stream coming in from the server. I have coded the first 4 bytes (in hexadecimal) of message coming in from the server to specify the length