RejectedSoftware Forums

Sign up

TCPConnection -> stdout

Hi,

What's the easiest way to redirect all of the data from a TCPConnection to std.stdout?

Luís

Re: TCPConnection -> stdout

On 09/13/2014 10:17 PM, Luís Marques wrote:

Hi,

What's the easiest way to redirect all of the data from a TCPConnection to std.stdout?

Luís

There is an adapter in vibe.stream.wrapper.

import std.algorithm, std.stdio, vibe.stream.wrapper;

auto stream = connectTCP("localhost", 8080);
StreamInputRange(stream).copy(stdout.lockingTextWriter());

http://vibed.org/api/vibe.stream.wrapper/StreamInputRange
http://dlang.org/library/std/stdio/File.lockingTextWriter.html
http://dlang.org/library/std/algorithm/copy.html

Re: TCPConnection -> stdout

On Sun, 14 Sep 2014 19:55:07 +0200, Martin Nowak wrote:

http://vibed.org/api/vibe.stream.wrapper/StreamInputRange
http://dlang.org/library/std/stdio/File.lockingTextWriter.html
http://dlang.org/library/std/algorithm/copy.html

Ah. The problem was that I had found the stream stuff in vibe.core.stream. Since that package had NullOutputStream, I thought that if any other utility adapters existed they would reside there. I missed vibe.stream.

Thanks!

Re: TCPConnection -> stdout

On Sun, 14 Sep 2014 18:06:32 GMT, Luís Marques wrote:

On Sun, 14 Sep 2014 19:55:07 +0200, Martin Nowak wrote:

http://vibed.org/api/vibe.stream.wrapper/StreamInputRange
http://dlang.org/library/std/stdio/File.lockingTextWriter.html
http://dlang.org/library/std/algorithm/copy.html

Ah. The problem was that I had found the stream stuff in vibe.core.stream. Since that package had NullOutputStream, I thought that if any other utility adapters existed they would reside there. I missed vibe.stream.

Thanks!

Another alternative (which doesn't block the event loop at the expense of creating an additional thread internally):

import vibe.stream.stdio;
auto stdout = new StdoutStream;
auto stream = connectTCP("localhost", 8080); 
stdout.write(stream);