Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module ConnectionHandler
- open System
- open System.Net.Sockets
- open System.Text
- let rec async_print_stream (stream : NetworkStream) =
- async {
- let buf : byte array = Array.zeroCreate 256
- match stream.Read(buf,0,256) with
- | count when count > 0 ->
- let str = Encoding.ASCII.GetString buf
- Console.WriteLine(str)
- Console.WriteLine("Got Something")
- | _ -> ()
- return! async_print_stream stream
- }
- let socket = new TcpClient()
- socket.Connect("192.168.4.10", 6014)
- Console.WriteLine(socket.Connected)
- let cad_stream = socket.GetStream()
- match cad_stream.CanRead with
- | true ->
- let result_string = "ready to read"
- Console.WriteLine(result_string)
- async_print_stream cad_stream |> Async.RunSynchronously
- | false -> Console.WriteLine("Not Ready to read")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement