我将此 c#代码转换为 powershell脚本
时遇到问题var server = new WebSocketServer("ws://localhost:8181");
server.Start(socket =>
{
socket.OnOpen = () => Console.WriteLine("Open!");
socket.OnClose = () => Console.WriteLine("Close!");
socket.OnMessage = message => socket.Send(message);
});
我已经在内存中加载了相关的dll,特别需要帮助理解和转换这段代码。
server.Start(socket =>
{
socket.OnOpen = () => Console.WriteLine("Open!");
socket.OnClose = () => Console.WriteLine("Close!");
socket.OnMessage = message => socket.Send(message);
});
答案 0 :(得分:1)
如果您已导入类型,则可以执行此操作。不确定它是否有效,因为我不知道你有哪些确切的参数类型。
$server = New-Object -TypeName WebSocketServer -ArgumentList "ws://localhost:8181"
$server.Start([Action[Socket]] {
param([Socket]$s)
$s.OnOpen = [Action] { Write-Host "Open!" }
$s.OnClose = [Action] { Write-Host "Close!" }
$s.OnMessage = [Action[string]] {
param([string]$message)
$s.Send($message)
}
})