You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An odd OS difference. On Unix (macOS and Linux), one can pass just a port number as the Address into tcp_connect to connect to a local port. On Windows, the same call gives an error, so one has to explicitly pass '':Port or localhost:Port instead.
1 ?- use_module(library(socket)).
true.
2 ?- tcp_connect(8080, Stream, []).
ERROR: Socketerror: CannotassignrequestedaddressERROR: In:
ERROR: [14] throw(error(socket_error(wsaeaddrnotavail,'Cannot assign requested address'),_1286))
ERROR: [12] catch('<garbage_collected>','<garbage_collected>','<garbage_collected>') atc:/programfiles/swi-prolog/stable/boot/init.pl:562
ERROR: [10] socket:tcp_connect(8080,_1352,[]) atc:/programfiles/swi-prolog/stable/library/socket.pl:384
ERROR: [9] toplevel_call('<garbage_collected>') atc:/programfiles/swi-prolog/stable/boot/toplevel.pl:1158
ERROR:
ERROR: Note: someframesaremissingduetolast-calloptimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.
3 ?- tcp_connect('':8080, Stream, []).
Stream = <stream>(00000000033355D0,0000000003335C30).
According to the docs, tcp_connect/3 actually requires an explicit hostname and shouldn't accept a plain port:
Address is either a Host:Port term or a file name (atom or string). The latter connects to an AF_UNIX socket and requires unix_domain_socket/1.
So the fix would be either to document the Unix behavior and support plain port numbers on Windows as well, or to check and disallow plain port numbers on all platforms. I would vote for the first option, because it avoids breaking existing code - and would also match what SICStus' library(sockets) does 🙂
The text was updated successfully, but these errors were encountered:
I see. In fact, using Wine I get something different: tcp_connect/3 with just a port succeeds, with '':Port raises an exception and using localhost:Port works fine too. I've pushed a patch to initialize the complete address info. No idea how that will work out on the various platforms. It can't be bad to avoid using uninitialized memory though 😄
An odd OS difference. On Unix (macOS and Linux), one can pass just a port number as the
Address
intotcp_connect
to connect to a local port. On Windows, the same call gives an error, so one has to explicitly pass'':Port
orlocalhost:Port
instead.According to the docs,
tcp_connect/3
actually requires an explicit hostname and shouldn't accept a plain port:So the fix would be either to document the Unix behavior and support plain port numbers on Windows as well, or to check and disallow plain port numbers on all platforms. I would vote for the first option, because it avoids breaking existing code - and would also match what SICStus'
library(sockets)
does 🙂The text was updated successfully, but these errors were encountered: