Skip to content

Commit 6fec299

Browse files
committed
Fixed bug in NetworkEvents::createZmqContext. Added Python example script for sending network events.
1 parent b433337 commit 6fec299

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from __future__ import print_function, unicode_literals
2+
3+
import zmq
4+
5+
try:
6+
raw_input
7+
except NameError:
8+
# Python 3
9+
raw_input = input
10+
11+
12+
def run(hostname='localhost', port=5556):
13+
with zmq.Context() as ctx:
14+
with ctx.socket(zmq.REQ) as sock:
15+
sock.connect('tcp://%s:%d' % (hostname, port))
16+
while True:
17+
try:
18+
req = raw_input('> ')
19+
sock.send_string(req)
20+
rep = sock.recv_string()
21+
print(rep)
22+
except EOFError:
23+
print() # Add final newline
24+
break
25+
26+
27+
if __name__ == '__main__':
28+
run()

Source/Processors/NetworkEvents/NetworkEvents.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ void NetworkEvents::run()
449449
if (rc != 0)
450450
{
451451
// failed to open socket?
452-
std::cout << "Failed to open socket." << std::endl;
452+
std::cout << "Failed to open socket: " << zmq_strerror(zmq_errno()) << std::endl;
453453
return;
454454
}
455455

@@ -562,7 +562,7 @@ void NetworkEvents::loadCustomParametersFromXml()
562562
void NetworkEvents::createZmqContext()
563563
{
564564
#ifdef ZEROMQ
565-
if (zmqcontext != nullptr)
565+
if (zmqcontext == nullptr)
566566
zmqcontext = zmq_ctx_new(); //<-- this is only available in version 3+
567567
#endif
568568
}

0 commit comments

Comments
 (0)