How to output continuous objects

Welcome Forums General PowerShell Q&A How to output continuous objects

Viewing 0 reply threads
  • Author
    Posts
    • #208995
      OK
      Participant
      Topics: 9
      Replies: 20
      Points: 122
      Rank: Participant
      
      [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()
      }
      
      }

      I get no results or discontinuities

       

      • This topic was modified 2 months, 3 weeks ago by OK.
Viewing 0 reply threads
  • You must be logged in to reply to this topic.