users-prolog
[Top][All Lists]
Advanced

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

Re: Socket woes...


From: Salvador Pinto Abreu
Subject: Re: Socket woes...
Date: Sat, 20 Jul 2013 23:44:22 +0100

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]