Advertisement
Guest User

woo

a guest
Jun 16th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.85 KB | None | 0 0
  1. module ConnectionHandler
  2.  
  3. open System
  4. open System.Net.Sockets
  5. open System.Text
  6.  
  7. let rec async_print_stream (stream : NetworkStream) =
  8.     async {
  9.         let buf : byte array = Array.zeroCreate 256
  10.         match stream.Read(buf,0,256) with
  11.         | count when count > 0 ->
  12.             let str = Encoding.ASCII.GetString buf
  13.             Console.WriteLine(str)
  14.             Console.WriteLine("Got Something")
  15.         | _ -> ()
  16.         return! async_print_stream stream
  17.     }
  18.  
  19. let socket = new TcpClient()
  20. socket.Connect("192.168.4.10", 6014)
  21. Console.WriteLine(socket.Connected)
  22.  
  23. let cad_stream = socket.GetStream()
  24.  
  25. match cad_stream.CanRead with
  26. | true ->
  27.     let result_string = "ready to read"
  28.     Console.WriteLine(result_string)
  29.     async_print_stream cad_stream |> Async.RunSynchronously
  30. | false -> Console.WriteLine("Not Ready to read")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement