Created
March 20, 2015 06:43
-
-
Save Jaykul/d0ee7603a6dff6ffecac to your computer and use it in GitHub Desktop.
PowerShell NetMQ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set up the proxy forwarder ... | |
Add-Type -path .\NetMQ\lib\net40\NetMQ.dll | |
Start-Job { | |
try { | |
$context = [NetMQ.NetMQContext]::Create() | |
$publisher = $context.CreateXPublisherSocket() | |
$subscriber = $context.CreateXSubscriberSocket() | |
$publisher.Bind("tcp://127.0.0.1:50007"); | |
$subscriber.Bind("tcp://127.0.0.1:50014"); | |
$proxy = [NetMQ.Proxy]::new($subscriber, $publisher, $null) | |
$proxy.Start(); | |
} finally { | |
$context.Dispose() | |
$publisher.Dispose() | |
$subscriber.Dispose() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set up a Publisher | |
Add-Type -path .\NetMQ\lib\net40\NetMQ.dll | |
try { | |
$context = [NetMQ.NetMQContext]::Create() | |
$publisher = $context.CreatePublisherSocket() | |
$publisher.Connect("tcp://127.0.0.1:50014"); | |
function Send-Message { | |
param($Message, $Channel = 1) | |
[NetMQ.OutgoingSocketExtensions]::Send( $publisher, "CHANNEL$Channel", $false, $true ) | |
[NetMQ.OutgoingSocketExtensions]::Send( $publisher, $Message ) | |
} | |
Send-Message "Hello World" | |
} finally { | |
$context.Dispose() | |
$publisher.Dispose() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set up a listener | |
Add-Type -path .\NetMQ\lib\net40\NetMQ.dll | |
try { | |
$context = [NetMQ.NetMQContext]::Create() | |
$subscriber = $context.CreateSubscriberSocket() | |
$subscriber.Connect("tcp://127.0.0.1:50007"); | |
$publisher.Connect("tcp://127.0.0.1:50014"); | |
$subscriber.Subscribe("CHANNEL1") | |
$subscriber.Subscribe("CHANNEL2") | |
while ($true) | |
{ | |
# This is always going to pull either "IRC" or "BOT" ... | |
$Channel = [NetMQ.ReceivingSocketExtensions]::ReceiveString($subscriber) | |
$message = [NetMQ.ReceivingSocketExtensions]::ReceiveString($subscriber) | |
Write-Host "[$Channel]: $message" | |
} | |
} finally { | |
$context.Dispose() | |
$subscriber.Dispose() | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment