Hey, unfortunately there was no response to my issue on GitHub, so maybe someone over here got an idea what the problem might be:
The example publisher in the Basics section of the ZMQ Guide crashes if put in a function. See this:
using ZMQ
function main()
context = Context()
socket = Socket(context, PUB)
bind(socket, "tcp://*:5556")
while true
zipcode = rand(10000:99999)
temperature = rand(-80:135)
relhumidity = rand(10:60)
message = "$zipcode $temperature $relhumidity"
send(socket, message)
yield()
end
close(socket)
close(context)
end
if abspath(PROGRAM_FILE) == @__FILE__
main()
end
Which results in:
ERROR: LoadError: StateError("Unknown error")
Stacktrace:
[1] _send(socket::Socket, zmsg::Base.RefValue{ZMQ._Message}, more::Bool)
@ ZMQ C:\Users\toby\.julia\packages\ZMQ\lrABE\src\comm.jl:14
[2] send(socket::Socket, data::String; more::Bool)
@ ZMQ C:\Users\toby\.julia\packages\ZMQ\lrABE\src\comm.jl:45
[3] send
@ C:\Users\toby\.julia\packages\ZMQ\lrABE\src\comm.jl:42 [inlined]
[4] main()
@ Main C:\Users\toby\Workspaces\ZMQTest.jl\publisher_basics.jl:13
[5] top-level scope
@ C:\Users\toby\Workspaces\ZMQTest.jl\publisher_basics.jl:22
in expression starting at C:\Users\toby\Workspaces\ZMQTest.jl\publisher_basics.jl:21
Everthing is fine if the code is not encapsulated inside a function:
using ZMQ
context = Context()
socket = Socket(context, PUB)
bind(socket, "tcp://*:5556")
while true
zipcode = rand(10000:99999)
temperature = rand(-80:135)
relhumidity = rand(10:60)
message = "$zipcode $temperature $relhumidity"
send(socket, message)
yield()
end
close(socket)
close(context)
I’m on Windows 11 running Julia v1.8.5 with ZMQ v1.2.2.
Any idea what I could have done wrong? It seems to me like a rather simple change that couldn’t really hurt, but apparently I have been proven wrong and could have misused the API.