Last active
December 9, 2018 12:12
-
-
Save standarddeviant/a6ff8c04743e9c1a76ed939b5c97297b to your computer and use it in GitHub Desktop.
Julia Network listen/connect on IPv4(0)
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
# On a normal machine, this should run just fine | |
# But some machines require an agressive network security policiy | |
# And this simple test will fail | |
using Sockets | |
TEST_PORT = 12567 | |
# Listen asynchronously | |
listen_task = @async begin | |
server=listen(IPv4(0), TEST_PORT); @info "Listening $(IPv4(0)):$(TEST_PORT)" | |
insock = accept(server); @info "Accepted $(insock)" | |
close(insock); @info "Closed insock" | |
close(server); @info "Closed server" | |
end | |
sleep(1) # on some systems, the server needs a small sleep to actually listen | |
# without this sleep, the below connect call will error with "Connection refused" | |
# Connect to asynchronous listen | |
asock = connect(getipaddr(), TEST_PORT); @info "Successful connect" | |
wait(listen_task); @info "listen_task ended" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment