How to output continuous objects

[pre]

[CmdletBinding()]
param()
Try{
Do{
$URL = ‘wss://topurl.cn:9001’
$WS = New-Object System.Net.WebSockets.ClientWebSocket
$CT = New-Object System.Threading.CancellationToken
$WS.Options.UseDefaultCredentials = $true

$Conn = $WS.ConnectAsync($URL, $CT)
#$Conn
While (!$Conn.IsCompleted) {
Start-Sleep -Milliseconds 100
}
write-verbose “Connected to $($URL)”
$Size = 1024*20
$Array = [byte[]] @(,0) * $Size

$action=@’
{“type”:“update”,“data”:{“domainFrom”:“3.weiwei.in”},“char”:“H0l0”}
'@

$Command = [System.Text.Encoding]::UTF8.GetBytes($action) #“ACTION=Command”
$Send = New-Object System.ArraySegment[byte] -ArgumentList @(,$Command)
$Conn = $WS.SendAsync($Send, [System.Net.WebSockets.WebSocketMessageType]::Text, $true, $CT)

While ($WS.State -eq ‘Open’) {
$Array = [byte[]] @(,0) * $Size
$Recv = [System.ArraySegment[byte]]::new($Array)
$Conn = $WS.ReceiveAsync($Recv, $CT)
While (!$Conn.IsCompleted) {
#Write-Host “Sleeping for 100 ms”
Start-Sleep -Milliseconds 100
}

$string=[System.Text.Encoding]::utf8.GetString($Recv.array)
if($string){
$sd=$string |ConvertFrom-Json
if($SD.type -eq ‘identity’){
$sd.data.history |select name,msg #|Out-default #|ft
}elseif($SD.type -eq ‘chat’){
$sd.data |select name,msg #|Out-String -Stream #|ft -HideTableHeaders #NoNewline
}
}

}
sleep 20
} Until ($WS.State -ne ‘Open’)

}Finally{

If ($WS) {
Write-Host “Closing websocket”
$WS.Dispose()
}

}[/pre]

I get no results or discontinuities