[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Newbie: redundant connection
From: |
Detlef Sax |
Subject: |
RE: Newbie: redundant connection |
Date: |
Sun, 17 Jun 2001 16:18:33 +0200 (CEST) |
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