473,394 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

get a line of text from a socket...

If you don't know how long your input data is going to be how can you
at least treat it a text line at a time... like looking for new line in
the data... Right now recv blocks. Yes I could do a select, but the
examples seem a bit complicated for a simple line oriented input...

Aug 25 '06 #1
6 3486
In <11**********************@m79g2000cwm.googlegroups .com>, KraftDiner
wrote:
If you don't know how long your input data is going to be how can you
at least treat it a text line at a time... like looking for new line in
the data... Right now recv blocks. Yes I could do a select, but the
examples seem a bit complicated for a simple line oriented input...
This is already done in the `asyncore` and `asynchat` modules of the
standard library.

Ciao,
Marc 'BlackJack' Rintsch
Aug 25 '06 #2

Marc 'BlackJack' Rintsch wrote:
In <11**********************@m79g2000cwm.googlegroups .com>, KraftDiner
wrote:
If you don't know how long your input data is going to be how can you
at least treat it a text line at a time... like looking for new line in
the data... Right now recv blocks. Yes I could do a select, but the
examples seem a bit complicated for a simple line oriented input...

This is already done in the `asyncore` and `asynchat` modules of the
standard library.

Ciao,
Marc 'BlackJack' Rintsch
Thanks I can't seem to get this example to do anything except sit
there....
http://docs.python.org/lib/asyncore-example.html
And still it seems like a lot of work for a simple send/expect script.
I got the makefile to work.. there is a readline function how does one
use writelines to write one single line?

Aug 26 '06 #3
KraftDiner wrote:
Thanks I can't seem to get this example to do anything except sit
there....
http://docs.python.org/lib/asyncore-example.html
Yeah, the example code, by itself, will just sit there.
As an example, it should probably include the calls to make it
do something. Try adding the following lines to the given code:

http_client('www.python.org', '/')
asyncore.loop()

The call: "asyncore.loop()" is what says to stop just sitting
there and do something.

And still it seems like a lot of work for a simple send/expect script.
I got the makefile to work.. there is a readline function how does one
use writelines to write one single line?
I don't yet have my head around what you are asking. Reading
exactly up to end-of-line from a socket can be a bit tricky,
but I think I can explain. Managing multiple input sources and
their blocking behavior is a basic problem -- so basic that we've
already examined and debated the alternatives. Writing exactly
one line is trivial.

I found Marc 'BlackJack' Rintsch's response a bit misleading.
The asyncore module offers nothing to read a line. The asynchat
module will respond to lines if you pass set_terminator() the
end-of-line marker. I had to read both the doc and the source
to figure out what should work.

Sybren Stuvel pointed out socket.makefile(), which will read up
to the end of line, but does not play nice with others. Its
local buffering pretty much breaks select(). If you set any
timeout and the timeout raises, the documented interface does
not provide any way to tell what data was sent and received.

Jean-Paul Calderone suggested Twisted; it has a lot of fans, and
I'm not competent to say how well it would work in this case.
I've never been willing, nor seen the need, to re-write all code
in Twisted's deferred form.

--
--Bryan
Aug 26 '06 #4

Bryan Olson wrote:
KraftDiner wrote:
Thanks I can't seem to get this example to do anything except sit
there....
http://docs.python.org/lib/asyncore-example.html

Yeah, the example code, by itself, will just sit there.
As an example, it should probably include the calls to make it
do something. Try adding the following lines to the given code:

http_client('www.python.org', '/')
asyncore.loop()

The call: "asyncore.loop()" is what says to stop just sitting
there and do something.

What makes asyncore.loop exit?

And still it seems like a lot of work for a simple send/expect script.
I got the makefile to work.. there is a readline function how does one
use writelines to write one single line?

I don't yet have my head around what you are asking. Reading
exactly up to end-of-line from a socket can be a bit tricky,
but I think I can explain. Managing multiple input sources and
their blocking behavior is a basic problem -- so basic that we've
already examined and debated the alternatives. Writing exactly
one line is trivial.

I found Marc 'BlackJack' Rintsch's response a bit misleading.
The asyncore module offers nothing to read a line. The asynchat
module will respond to lines if you pass set_terminator() the
end-of-line marker. I had to read both the doc and the source
to figure out what should work.

Sybren Stuvel pointed out socket.makefile(), which will read up
to the end of line, but does not play nice with others. Its
local buffering pretty much breaks select(). If you set any
timeout and the timeout raises, the documented interface does
not provide any way to tell what data was sent and received.

Jean-Paul Calderone suggested Twisted; it has a lot of fans, and
I'm not competent to say how well it would work in this case.
I've never been willing, nor seen the need, to re-write all code
in Twisted's deferred form.

--
--Bryan
Aug 28 '06 #5
"KraftDiner" wrote:
What makes asyncore.loop exit?
as most other things you ask about, that's explained in the documentation:

http://docs.python.org/lib/module-asyncore.html

loop(...)

Enter a polling loop that terminates after count passes
or all open channels have been closed.

</F>

Aug 28 '06 #6

Sybren Stuvel wrote:
KraftDiner enlightened us with:
What makes asyncore.loop exit?

Why ask questions about something you're unable to use, when I've
given you something that does work?
Who said it didn't work?
Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Aug 31 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Wade Leftwich | last post by:
Every couple of months I have a use for the experimental 'scanner' object in the re module, and when I do, as I did this morning, it's really handy. So if anyone is counting votes for making it a...
13
by: Dan V. | last post by:
How do I create a one line text file with these control codes? e.g.: 144 = 0x90 and 147 = 0x93? I am trying to create a one line text file with these characters all one one row with no spaces. ...
3
by: Jow Blow | last post by:
I am trying to make a word wrap type function for a multi line text box field that will be saved to a text file. The word wrap property looks good in the app but when saved to a text file the line...
1
by: Mike L | last post by:
This is for a Win form. I am able to send a string to my multi line text box, but I want the string to have hard returns in it. Here is my code for the string. string s =...
3
by: Kieran Breen | last post by:
Hiya, I was just wondering if anyone knows how to impose a maximum length on a muti line text box in asp.net. There is a parameter for this but even when its set it dosent seem to make any...
9
by: C.K | last post by:
Can I enter a two-line text description on a button, chr(13) doesn't seem to do anything ?
1
by: amruta | last post by:
I need to write something like this in the multi line text box dynamically as the value is obtained. how can i do it example: abce 1232 qwert asdfg qwqw ghdjhfj ...
8
by: MLH | last post by:
Am trying to import 20,000+ lines of text in a file FTP'd from a UNIX platform to windows via FTP session in a DOS box. About 2000 records have multiple lines in them separated by CRLF's. ...
8
by: cj | last post by:
I use multi-line text boxes with vertical scroll bars in several of my programs to display log information as the programs run. Once the text more than fills the visible portion of the textbox I...
2
by: shihab | last post by:
I have created two text boxes,One is single line text box other is multiline. On button click i want to 'add text from single text box to Multiline text box'one by one. please give solution for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.