users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fw: Newbie: redundant connection


From: carlos calderon
Subject: Fw: Newbie: redundant connection
Date: Mon, 18 Jun 2001 11:46:46 +0100

Apologise if you get this message twice.
----- Original Message -----
From: "carlos calderon" <address@hidden>
To: "Detlef Sax" <address@hidden>
Cc: <address@hidden>
Sent: Monday, June 18, 2001 11:04 AM
Subject: Re: Newbie: redundant connection


>
> ----- Original Message -----
> From: "Detlef Sax" <address@hidden>
> To: "carlos calderon" <address@hidden>
> Cc: <address@hidden>
> Sent: Sunday, June 17, 2001 3:18 PM
> Subject: RE: Newbie: redundant connection
>
>
>
> > On 17-Jun-01 carlos calderon wrote:
> > [...]
> >  I wrote the following piece of code:
> > > /*Solution is a list*/
> > > sendlist(Solution) :-
> > >
> > > /*create sockets*/
> > > socket('AF_INET',Socket),
> > > /*connect to server*/
> > > socket_connect(Socket,'AF_INET'('152.xxx.xxx.xxx', 1936),
> > > StreamInput,StreamOuput),
> >
> > Try to insert:
> > add_stream_alias(Socket, socket),
> > add_stream_alias(StreamInput, aliI),
> > add_stream_alias(StreamInput, aliO),
> >
> > >/*where xxx is my server's IP address*/
> > > set_stream_buffering(StreamOutput,none),
> >
> > set_stream_buffering(aliO,none),
> >
> > Comment out next 2 lines:
> > > '$stream'(I) = StreamOutput,
> > > write2server(Solution,'$stream'(I)),
> >
> > write2server(Solution,aliO),
> >
> > > /*close socket*/
> > > socket_close(Socket).
> >
> > GNU Prolog (1.2.6) Documentation 6.28.2:
> > socket_close(Socket)
> > [...]This predicate should not be used if Socket has given rise to a
> stream,
> > e.g. by socket_connect/2 (section 6.28.5). In that case simply use
close/2
> > (section 6.10.7) on the associated stream.
> >
> > add_somewhere_in_your_code_to_close_after_testing_all_finished :-
> > % close all streams and sockets
> >         close(aliI),
> >         close(aliO),
> >         close(socket).
> >
> > Whenever possible I use aliases for streams, because my hair get more
grey
> > by trying operations with '$streams'. I don't care the additional space
> > wasted.
> >
> > HTH & greetings
> > Detlef
> >
 Thanks Detlef...

 I agree with about using aliases whenever possible ..I didn't know about
 add_stream_alias

 However, when I do
 add_stream_alias(Socket,socket)
 [..]
 close(Socket)
 it gives me an error:
 uncaught exception: error(domain_error(stream_or_alias,6),
 add_stream_alias/2).
 according to the manual this happens because SorA is neither a variable nor
 a stream-term or alias.

 I knew about socket-close(Socket). The manual recommends to use close/2
but,
 it seems to me, that that only closes the stream. It doesn't destroy the
 socket (so when it tries to send a new list it gives you a redundant
 connection error -because of the socket_connect predicate).
 I have found that both SICStus adn Quintus Prolog have a socket library
 module with  socket_destroy(Socket) as a built-in predicate. Then a typical
 client code would be:
 client(Host,Port) :-
         socket_create(....),
         socket_connect(...),
         communicate_with_server(..) /*to implement the communication
 protocol with the server*/
         socket_destroy(Socket) /*the socket is destroyed*/

 I guess my question is:
 how do u destroy a socket in GNU Prolog?
 close(Socket) doesn't work.

 Thanks..
>
>
>
>
> > _______________________________________________
> > Users-prolog mailing list
> > address@hidden
> > http://mail.gnu.org/mailman/listinfo/users-prolog
> >
>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]