Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #38625
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!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.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'algorithm': 0.03; 'subject:Python': 0.05; 'bytes.': 0.07; 'try:': 0.07; 'python': 0.09; '16)': 0.09; 'length.': 0.09; 'valueerror': 0.09; 'received:124.108': 0.16; 'true:': 0.16; 'byte': 0.17; 'bytes': 0.17; 'implementing': 0.17; 'specify': 0.17; '(in': 0.18; 'translate': 0.20; "i've": 0.23; 'second': 0.24; 'implemented': 0.27; 'i.e.': 0.27; 'coded': 0.29; 'str': 0.29; 'this.': 0.29; "i'm": 0.29; 'server.': 0.32; 'print': 0.32; 'to:addr:python- list': 0.33; 'hi,': 0.33; 'received:172.16': 0.34; 'server': 0.35; 'except': 0.36; 'skip:{ 10': 0.36; 'client': 0.36; 'charset:us- ascii': 0.36; 'to:addr:python.org': 0.39; 'help': 0.40; 'first': 0.61; 'side': 0.61; 'header:Message-Id:1': 0.62; 'received:': 0.62; 'stuck': 0.65; 'receive': 0.71; 'payload': 0.84; 'received:my': 0.93 |
| From | Ihsan Junaidi Ibrahim <ihsan@grep.my> |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | quoted-printable |
| Subject | Python recv loop |
| Date | Mon, 11 Feb 2013 08:48:24 +0800 |
| To | python-list@python.org |
| Mime-Version | 1.0 (Mac OS X Mail 6.2 \(1499\)) |
| X-Mailer | Apple Mail (2.1499) |
| 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.1612.1360544258.2939.python-list@python.org> (permalink) |
| Lines | 36 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1360544258 news.xs4all.nl 6852 [2001:888:2000:d::a6]:50573 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:38625 |
Show key headers only | View raw
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 of the message payload i.e. 0xad{...}
I've managed to receive and translate the message length until I reach my second recv which I readjusted the buffer size to include the new message length.
However that failed and recv received 0 bytes. I implemented the same algorithm on the server side using C and it work so appreciate if you can help me on this.
# receive message length
print 'receiving data'
mlen = sock.recv(4)
try:
nbuf = int(mlen, 16)
except ValueError as e:
print 'invalid length type'
return -1
while True:
buf = sock.recv(nbuf)
if not buf:
break
slen = len(buf)
str = "{0} bytes received: {1}".format(slen, buf)
print str
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll 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