www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Using std.net.curl to stream data

reply "Trollgeir" <asgeir.berland gmail.com> writes:
I'm having some trouble trying to stream data to my plot.ly graph:
https://plot.ly/62/~Trollgeir/

The API:  https://plot.ly/streaming/

I am able to post messages that get recorded into the stream 
live, although right after curl uploads it, it just seems to wait 
for a response it's not getting, and eventually timeouts. Does 
anyone have any advice?

auto client = HTTP("stream.plot.ly");
client.addRequestHeader("plotly-streamtoken","e8bg6omat6");
client.verbose = true;

string msg = "{ \"x\": 500, \"y\": 500 } \n";
client.postData(msg);
client.perform;	
Jan 28 2015
parent "Chris Williams" <yoreanon-chrisw yahoo.co.jp> writes:
On Wednesday, 28 January 2015 at 14:18:38 UTC, Trollgeir wrote:
 I'm having some trouble trying to stream data to my plot.ly 
 graph:
 https://plot.ly/62/~Trollgeir/

 The API:  https://plot.ly/streaming/

 I am able to post messages that get recorded into the stream 
 live, although right after curl uploads it, it just seems to 
 wait for a response it's not getting, and eventually timeouts. 
 Does anyone have any advice?

 auto client = HTTP("stream.plot.ly");
 client.addRequestHeader("plotly-streamtoken","e8bg6omat6");
 client.verbose = true;

 string msg = "{ \"x\": 500, \"y\": 500 } \n";
 client.postData(msg);
 client.perform;	
You have to define a handler for HTTP.onReceive before calling HTTP.perform. It will receive ubyte arrays for each packet that comes in. For most purposes, you just copy that onto the end of a string in an external scope. But if you're streaming content, you'll need to do something more fancy.
Jan 28 2015