Last active
June 17, 2020 23:20
-
-
Save SLAVONchick/0de486c6586376f53d94cf5af0ce1e55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
open System.Net | |
open FSharp.Control.Tasks | |
open Pipelines.Sockets.Unofficial | |
use client = new TcpClient("127.0.0.1", 9851) | |
let pipe = StreamConnection.GetDuplex(client.GetStream()) | |
let scan = Encoding.UTF8.GetBytes "*2\r\n$4\r\nSCAN\r\n$36\r\n85AB427D-316C-4BD4-A511-6631851D212E\r\n" |> ReadOnlyMemory | |
task { | |
let! _ = pipe.Output.WriteAsync(scan) | |
let mutable isCompleted = false | |
while not isCompleted do | |
let! res = pipe.Input.ReadAsync() | |
for segment in res.Buffer do | |
printfn "%s" <| Encoding.UTF8.GetString segment.Span | |
pipe.Input.AdvanceTo(res.Buffer.Start, res.Buffer.End) | |
isCompleted <- res.IsCompleted | |
do! pipe.Input.CompleteAsync() | |
} | |
|> Async.AwaitTask | |
|> Async.RunSynchronously |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment