Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #38689

Re: Python recv loop

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ihsan@grep.my>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'messages.': 0.04; 'subsequent': 0.04; 'subject:Python': 0.05; 'json': 0.07; 'over,': 0.07; 'python': 0.09; 'length.': 0.09; 'logic': 0.09; 'second.': 0.09; 'cc:addr:python-list': 0.10; 'language': 0.14; '"1.0",': 0.16; '"2":': 0.16; '4-byte': 0.16; 'json,': 0.16; 'roy': 0.16; 'sure.': 0.16; 'unordered': 0.16; 'wrote:': 0.17; 'bytes': 0.17; 'certainly': 0.17; "shouldn't": 0.17; 'feb': 0.19; 'libraries': 0.22; "i'd": 0.22; 'cc:2**0': 0.23; 'statement': 0.23; 'cc:no real name:2**0': 0.24; 'second': 0.24; 'connected': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'i.e.': 0.27; 'is?': 0.27; 'fixed': 0.28; 'rest': 0.28; 'idea,': 0.29; "i'm": 0.29; 'running': 0.32; 'print': 0.32; '11,': 0.33; 'received:172.16': 0.34; 'server': 0.35; 'protocol': 0.35; 'something': 0.35; 'but': 0.36; 'client': 0.36; 'should': 0.36; 'charset:us-ascii': 0.36; 'possible': 0.37; 'beyond': 0.37; 'why': 0.37; 'sent:': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'application': 0.40; 'first': 0.61; 'header:Message-Id:1': 0.62; 'received:': 0.62; 'between': 0.63; 'messaging': 0.65; 'stuck': 0.65; 'talking': 0.66; 'smith': 0.71; 'dict,': 0.84; 'received:my': 0.93
Content-Type text/plain; charset=us-ascii
Mime-Version 1.0 (Mac OS X Mail 6.2 \(1499\))
Subject Re: Python recv loop
From Ihsan Junaidi Ibrahim <ihsan@grep.my>
In-Reply-To <roy-CC4632.21243210022013@news.panix.com>
Date Mon, 11 Feb 2013 22:56:32 +0800
Content-Transfer-Encoding quoted-printable
References <mailman.1612.1360544258.2939.python-list@python.org> <roy-CC4632.21243210022013@news.panix.com>
To Roy Smith <roy@panix.com>
X-Mailer Apple Mail (2.1499)
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1655.1360594595.2939.python-list@python.org> (permalink)
Lines 53
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1360594595 news.xs4all.nl 6868 [2001:888:2000:d::a6]:59044
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:38689

Show key headers only | View raw


Hi Roy,

On Feb 11, 2013, at 10:24 AM, Roy Smith <roy@panix.com> 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 sun.
> 
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 fixed 4-byte at the start of the message to indicate the message length.

Beyond the 4-bytes it is all JSON.

but if you have a better idea, i would certainly welcome it.

> Do you actually *know* what the value of nbuf is?  Is it possible that 
> (somehow) it's 0?  You should print (log, whatever), the value of nbuf, 
> just to make sure.

nbuf is printing the right bytes amount, I removed the print statement before I made the first post.

So to clarify, I added a print statement between the first recv and the second.

{"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", "appver": "1.0", "appid": "1.0", "data": {"1": "igb0", "2": "igb1", "ifcnt": "2"}}
receiving data
message length is 188
0 bytes received:

So the subsequent recv() call will be readjusted with 188 bytes buffer size so theoretically, recv shouldn't return 0.

The same logic that I used to send to the server from the python client that the server will readjust the second recv() call based on the length information. On this 2nd recv() call the server is able to obtain the rest of the messages.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Python recv loop Ihsan Junaidi Ibrahim <ihsan@grep.my> - 2013-02-11 08:48 +0800
  Re: Python recv loop Roy Smith <roy@panix.com> - 2013-02-10 21:24 -0500
    Re: Python recv loop Ihsan Junaidi Ibrahim <ihsan@grep.my> - 2013-02-11 22:56 +0800
      Re: Python recv loop Roy Smith <roy@panix.com> - 2013-02-11 21:44 -0500
    Re: Python recv loop MRAB <python@mrabarnett.plus.com> - 2013-02-11 15:11 +0000
    Re: Python recv loop Chris Angelico <rosuav@gmail.com> - 2013-02-12 02:24 +1100
    Re: Python recv loop Ihsan Junaidi Ibrahim <ihsan@grep.my> - 2013-02-12 09:41 +0800
    Re: Python recv loop Chris Angelico <rosuav@gmail.com> - 2013-02-12 13:20 +1100
    Re: Python recv loop MRAB <python@mrabarnett.plus.com> - 2013-02-12 03:09 +0000

csiph-web