Вверх ↑
Ответов: 189
Рейтинг: 27
#1: 2021-07-13 10:57:46 ЛС | профиль | цитата
Pavel писал(а):
Gunta, не получается проверить , после компиляции в консоли тишина. (ждал более минуты )

Странно, у меня всё работает, данные идут непрерывно.
Снимок.PNG
Какая у тебя система?

Попробуй, что будет писать в Memo?
Add(MainForm,2953706,70,140)
{
Caption="Test WebSocket Connections"
link(onCreate,12356033:doString,[])
}
Add(FormatStr,12356033,119,154)
{
Mask="$client_id = [System.GUID]::NewGuid()\r\n\r\n$recv_queue = New-Object 'System.Collections.Concurrent.ConcurrentQueue[String]'\r\n$send_queue = New-Object 'System.Collections.Concurrent.ConcurrentQueue[String]'\r\n\r\n$ws = New-Object Net.WebSockets.ClientWebSocket\r\n$cts = New-Object Threading.CancellationTokenSource\r\n$ct = New-Object Threading.CancellationToken($false)\r\n\r\n$connectTask = $ws.ConnectAsync("%1", $cts.Token)\r\n\r\n\r\ndo { Sleep(1) }\r\nuntil ($connectTask.IsCompleted)\r\n\r\n$recv_job = {\r\n param($ws, $client_id, $recv_queue)\r\n\r\n $buffer = [Net.WebSockets.WebSocket]::CreateClientBuffer(1024,1024)\r\n $ct = [Threading.CancellationToken]::new($false)\r\n $taskResult = $null\r\n\r\n while ($ws.State -eq [Net.WebSockets.WebSocketState]::Open) {\r\n $jsonResult = ""\r\n do {\r\n $taskResult = $ws.ReceiveAsync($buffer, $ct)\r\n while (-not $taskResult.IsCompleted -and $ws.State -eq [Net.WebSockets.WebSocketState]::Open) {\r\n [Threading.Thread]::Sleep(10)\r\n }\r\n\r\n $jsonResult += [Text.Encoding]::UTF8.GetString($buffer, 0, $taskResult.Result.Count)\r\n } until (\r\n $ws.State -ne [Net.WebSockets.WebSocketState]::Open -or $taskResult.Result.EndOfMessage\r\n )\r\n\r\n if (-not [string]::IsNullOrEmpty($jsonResult)) {\r\n #"Received message(s): $jsonResult" | Out-File -FilePath "logs.txt" -Append\r\n $recv_queue.Enqueue($jsonResult)\r\n }\r\n }\r\n }\r\n\r\n $send_job = {\r\n param($ws, $client_id, $send_queue)\r\n\r\n $ct = New-Object Threading.CancellationToken($false)\r\n $workitem = $null\r\n while ($ws.State -eq [Net.WebSockets.WebSocketState]::Open){\r\n if ($send_queue.TryDequeue([ref] $workitem)) {\r\n #"Sending message: $workitem" | Out-File -FilePath "logs.txt" -Append\r\n\r\n [ArraySegment[byte]]$msg = [Text.Encoding]::UTF8.GetBytes($workitem)\r\n $ws.SendAsync(\r\n $msg,\r\n [System.Net.WebSockets.WebSocketMessageType]::Binary,\r\n $true,\r\n $ct\r\n ).GetAwaiter().GetResult() | Out-Null\r\n }\r\n }\r\n }\r\n\r\n$recv_runspace = [PowerShell]::Create()\r\n$recv_runspace.AddScript($recv_job).\r\n AddParameter("ws", $ws).\r\n AddParameter("client_id", $client_id).\r\n AddParameter("recv_queue", $recv_queue).BeginInvoke() | Out-Null\r\n\r\n$send_runspace = [PowerShell]::Create()\r\n$send_runspace.AddScript($send_job).\r\n AddParameter("ws", $ws).\r\n AddParameter("client_id", $client_id).\r\n AddParameter("send_queue", $send_queue).BeginInvoke() | Out-Null\r\n\r\ntry {\r\n do {\r\n $msg = $null\r\n while ($recv_queue.TryDequeue([ref] $msg)) {\r\n $msg \r\n $hash = @{\r\n ClientID = $client_id\r\n Payload = "Wat"\r\n }\r\n\r\n $test_payload = New-Object PSObject -Property $hash\r\n $json = ConvertTo-Json $test_payload\r\n $send_queue.Enqueue($json)\r\n }\r\n } until ($ws.State -ne [Net.WebSockets.WebSocketState]::Open)\r\n}\r\nfinally {\r\n $closetask = $ws.CloseAsync(\r\n [System.Net.WebSockets.WebSocketCloseStatus]::Empty,\r\n "",\r\n $ct\r\n )\r\n\r\n do { Sleep(1) }\r\n until ($closetask.IsCompleted)\r\n $ws.Dispose()\r\n\r\n $recv_runspace.Stop()\r\n $recv_runspace.Dispose()\r\n\r\n $send_runspace.Stop()\r\n $send_runspace.Dispose()\r\n}"
link(onFString,1335603:doReplace,[])
link(Str1,6027970:Text,[])
}
Add(WinExec,2400366,217,140)
{
FileName="POWERSHELL"
Mode=0
Action="runas"
Point(doConsoleExec)
Point(onConsoleResult)
Point(onConsoleError)
Point(onConsoleTerminate)
link(onConsoleResult,14970828:doWork2,[])
link(onConsoleError,14970828:doWork3,[(263,167)])
link(onConsoleTerminate,2953706:doClose,[(256,174)(256,195)(60,195)(60,167)])
}
Add(Replace,1335603,168,154)
{
SubStr="""
DestStr="'"
link(onReplace,2400366:doConsoleExec,[])
}
Add(Charset,7504290,280,154)
{
link(onCharset,9397794:doAdd,[])
}
Add(Memo,9397794,329,154)
{
Left=550
Top=160
Align=5
ScrollBars=3
}
Add(VisualStrings,6027970,119,105)
{
Lines=#50:wss://ws.coincap.io/prices?assets=bitcoin,ethereum|
Width=270
}
Add(HubEx,14970828,259,154)
{
link(onEvent,7504290:doCharset,[])
}


Снимок2.PNG
карма: 4

0
Редактировалось 2 раз(а), последний 2021-07-13 11:04:47