users-prolog
[Top][All Lists]
Advanced

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

Re: Socket woes...


From: Sean Charles
Subject: Re: Socket woes...
Date: Sun, 21 Jul 2013 07:35:58 +0100

Hi Salvador,

Thanks for that reply. I had a read and it bears out what I experience; if I 
"wait" long enough then the problem does go away…it was not long before I 
realised that just terminating the Emacs prolog session and re-compiling into a 
new one wasn't the silver bullet!

To avoid such issues I now just use a range of ports instead, 10000, 100001 etc 
etc….running from a terminal window it's day!

:)
Thanks
Sean

On 20 Jul 2013, at 23:44, Salvador Pinto Abreu <address@hidden> wrote:

> i think sockets are not immediately closed by the OS, so you can't bind to 
> the same port right after closing it.
> 
> see http://lists.gnu.org/archive/html/users-prolog/2004-07/msg00007.html
> 
> one thing which could help is to add a foreign function interface to 
> setsockopt(2) which would set the SO_REUSEPORT on the socket, before doing 
> the bind.
> 
> -salvador
> 
> On Jul 20, 2013, at 23h08, Sean Charles <address@hidden> wrote:
> 
>> Using this code to start and stop a session:
>> 
>> session_start(Port) :-
>>        socket('AF_INET', S),
>>        socket_bind(S, 'AF_INET'(localhost, Port)),
>>        socket_listen(S, 0),
>>        socket_accept(S, Client, In, Out),
>>        format(Out, "~n~n>> Welcome to SKYNET, ~w~n", [Client]),
>>        cmd_loop(In, Out),
>>        close(In),close(Out),socket_close(S),
>>        format("Clean close~n", []).
>> 
>> I've done lots of socket coding with PHP and C/C++ and usually the safest 
>> bet is to get the client to terminate the connection first to avoid and 
>> issues within the TCP driver regarding wait states and things but being new 
>> to prolog still I wonder if I've done something silly in my code that I 
>> can't see?
>> 
>> I am using telnet to connect, all foes well until I type "bye". The program 
>> terminates, tells me it was a clean close but when I try to run again:
>> 
>> session_start(10000).
>> uncaught exception: error(system_error('Address already in 
>> use'),socket_bind/2)
>> 
>> Bummer.
>> 
>> Any suggestions?
>> 
>> _______________________________________________
>> Users-prolog mailing list
>> address@hidden
>> https://lists.gnu.org/mailman/listinfo/users-prolog
> 




reply via email to

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