Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Read Lines from a Socket

Moderators: larsivi kris

Posted: 05/24/08 00:25:43

I'm writing a network application that will need to read lines of text from a TCP Socket. I'm very unsure of how this should be done, should I have the socket store to a buffer somewhere and somehow pull out one line at a time or... the standard iteration approach that people use with text doesn't really work here...

Author Message

Posted: 05/24/08 03:18:17 -- Modified: 05/24/08 03:18:51 by

The iteration method works quite well with Tango. Here's one example:


void readLines (InputStream network)
    foreach (line; new LineInput(network))

The provided InputStream might be a SocketConduit

Posted: 05/24/08 04:19:18

Does that block until a line comes in? If not, will it iterate over previous lines received? That's what made me wonder if it would work.

Posted: 05/25/08 02:09:56

it will block if the provided input stream blocks (and they often do by default)