Powershell Websocket 客户端发送图像
Powershell Websocket Client Send Image
这里参考Vince Pike提供的解决方案:
How to use a Websocket client to open a long-lived connection to a URL, using PowerShell V2?
发送文本效果很好。如何发送 PNG 格式或二进制数据等图像?
发送文本的示例来源:
$Size = 1024
$Array = [byte[]] @(,0) * $Size
$Message = "Sample Message"
$Command = [System.Text.Encoding]::UTF8.GetBytes($Message)
$Send = New-Object System.ArraySegment[byte] -ArgumentList @(,$Command)
$Conn = $WS.SendAsync($Send, [System.Net.WebSockets.WebSocketMessageType]::Text, $true, $CT)
While (!$Conn.IsCompleted) {
Start-Sleep -Milliseconds 100
}
@Theo 的评论已解决:
[Byte[]]$Command = [System.IO.File]::ReadAllBytes(<Absolute\Path\To\The\Image\Or\Binary\File>)
$Conn = $WS.SendAsync($Send, [System.Net.WebSockets.WebSocketMessageType]::Binary, $true, $CT)
这里参考Vince Pike提供的解决方案: How to use a Websocket client to open a long-lived connection to a URL, using PowerShell V2?
发送文本效果很好。如何发送 PNG 格式或二进制数据等图像?
发送文本的示例来源:
$Size = 1024
$Array = [byte[]] @(,0) * $Size
$Message = "Sample Message"
$Command = [System.Text.Encoding]::UTF8.GetBytes($Message)
$Send = New-Object System.ArraySegment[byte] -ArgumentList @(,$Command)
$Conn = $WS.SendAsync($Send, [System.Net.WebSockets.WebSocketMessageType]::Text, $true, $CT)
While (!$Conn.IsCompleted) {
Start-Sleep -Milliseconds 100
}
@Theo 的评论已解决:
[Byte[]]$Command = [System.IO.File]::ReadAllBytes(<Absolute\Path\To\The\Image\Or\Binary\File>)
$Conn = $WS.SendAsync($Send, [System.Net.WebSockets.WebSocketMessageType]::Binary, $true, $CT)