I do this in Unix with the netcat tool:
$ netcat gh05.geekhosters.com 50001
{ "id": 0, "method": "server.version", "params": [ "1.9.5", "0.6" ] }
The result, at the time of writing, is the server replying to me this:
{"id": 0, "result": "1.0"}
Great! Now I want to do the same in F#.
I tried this:
let rec asyncPrintResponse (stream: System.Net.Sockets.NetworkStream) =
async {
let response = stream.ReadByte() |> Char.ConvertFromUtf32
Console.Write(response)
return! asyncPrintResponse stream
}
let TcpClientTest() =
let client = new System.Net.Sockets.TcpClient()
client.Connect("gh05.geekhosters.com", 50001)
let stream = client.GetStream()
let bytes = System.Text.Encoding.UTF32.GetBytes("{ \"id\": 0, \"method\": \"server.version\", \"params\": [ \"1.9.5\", \"0.6\" ] }\n");
asyncPrintResponse stream |> Async.Start
stream.Write(bytes, 0, bytes.Length)
stream.Flush()
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(60.0))
The above prints, however:
{"error": "bad JSON"}
What am I doing wrong?