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# 重写它。我得到了这样的东西:
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"}} )