Error with wait_for_input when using with socket

56 views
Skip to first unread message

Saravanaraj Ayyampalayam

unread,
Jul 6, 2015, 12:30:12 AM7/6/15
to swi-p...@googlegroups.com
Hello,

I am trying to create a prolog TCP/IP socket server using SWI-Prolog. I am using SICStus compatible socket library to implement this server as we currently have this running under SICStus prolog. The error I am getting is as follows:

ERROR: wait_for_input/3: Domain error: `stream_or_alias' expected, found `'$socket'(0)' when I call socket_select/5. The manual says that wait_for_input should accept sockets and streams. Any recommendations?

Thanks,
-Raj

Jan Wielemaker

unread,
Jul 6, 2015, 2:41:50 AM7/6/15
to Saravanaraj Ayyampalayam, swi-p...@googlegroups.com
The emulation certainly has worked. Can you send a complete example?
Which OS? Windows is quite different from Unix here.

Cheers --- Jan

Saravanaraj Ayyampalayam

unread,
Jul 6, 2015, 3:53:07 PM7/6/15
to swi-p...@googlegroups.com, ans...@gmail.com
I am using SWI ver. 7.2.2 on Ubuntu. I've attached a simple version of our code. I get the same error when I run it on Windows.

Thanks,
-Raj
 
socket.pl

Saravanaraj Ayyampalayam

unread,
Jul 9, 2015, 10:50:56 AM7/9/15
to swi-p...@googlegroups.com
Hello Jan,

Any suggestions? 

Thanks,
-Raj 

Jan Wielemaker

unread,
Jul 9, 2015, 12:10:50 PM7/9/15
to Saravanaraj Ayyampalayam, swi-p...@googlegroups.com
On 07/09/15 16:50, Saravanaraj Ayyampalayam wrote:
>
> Any suggestions?

Not yet. Busy ... Hope to have a look soon ...

--- Jan

Jan Wielemaker

unread,
Jul 9, 2015, 12:30:44 PM7/9/15
to Saravanaraj Ayyampalayam, swi-p...@googlegroups.com
I had a quick look. First of all, you need to use expects_dialect as a
directive, so you start with:

:- expects_dialect(sicstus).
:- use_module(library(sockets)).

That doesn't fis this particular problem (but does for other compatibility
issues). Then, this emulation was written for a SICStus 3 program. That
runs using it, but don't ask full compatibility. Before you can hand a
SWI-Prolog socket to wait_for_input/3, you have to use tcp_open_socket/2
to get a stream. If you add that to service_socket/1, it actually waits
for a connection, to stumble on the non-existing service_stream/1 when
connecting. I don't know what that does. The typical way to deal with
sockets in SWI-Prolog is by means of threads.

I think you need a short study of SWI-Prolog's library(socket) and see
how to map the functionality you need.

Success --- Jan

Saravanaraj Ayyampalayam

unread,
Jul 9, 2015, 2:18:16 PM7/9/15
to swi-p...@googlegroups.com, ans...@gmail.com
Thanks Jan. I will adapt our code to use SWI sockets directly.

-Raj
Reply all
Reply to author
Forward
0 new messages