0
tcp_connection = tcp_connect('localhost', 20060)
// the server will always send responses on one line.
tcp_connection.on('line', function (line) {
json = json.decode(line)
if(json.result == "success") {
// etc, etc, etc.
}
})
tcp_connection.write("/api/subscribe?source={sourceName}&key={key}&show_previous={true|false}") //stream API request
嗯,这是我得到的伪代码,我不知道如何在C#中重写它。我有这样的事情:通过TCP订阅,反序列化每个接收的JSON行
TcpClient connection = new TcpClientWithTimeout(host, 20059, 20000).Connect();
NetworkStream stream = connection.GetStream();
我不知道如何更换“tcp_connection.on”,所以,我已经订阅了TCP后,每行我得到被使用json.decode转换成字符串(万一有帮助,响应格式为:
{"result":"success/error","source": "{source}","success":{"time": TIME RECEIVED,"line":"RECEIVED LINE"}})
谢谢,差不多工作。我会发布一个关于我的新问题的新问题。 – niklon 2013-02-24 14:39:41