This is a good question. I have encountered this also on a linux system. It looks like the port (in your case 5510) gets blocked for a long time. This can happen, when the socket is not closed. e.g. when the program aborts (with an error or even crashes) before the close. Or if the connection gets broken/interrupted. Why it takes so long for the system to detect this, I dont know. If you can always close the socet, then it should not happen and the port would get released.
If you want to write a real searver handling multiple connections, you should probably open the port only once and then handle all connections using FORK. There is an example program for this in the example program collection. See here: https://codeberg.org/kollo/X11-Basic_examples/src/branch/master/All/Internet/TCP/iserver.bas
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello Markus,
thank you for x11basic, i like it very much.
But now i have the following question.
My program uses socket communication by TCP
on a Samsung mini with Android 4.4 by cyanogenmod.
Listener=freefile()
OPEN "US",#Listener 1,"",5510 ! open socket
do
exit IF INP?(#1) ! wait for cliemt to connect
loop
Kanal=freefile()
OPEN "UA",#Kanal,"",1 ! open channel
Here i do some communication
until i exit a loop and ! do the work
finish the app with:
Close #Kanal ! close channel
Close #Listener ! close socket
Quit ! end the interpreter
But if i now restart the app, soon after quitting it,
i get an error on the line with the
Statement „OPEN "US",#Listener 1,"",5510“
ERROR at line … Address make_socket already in use
I tried to solve it by:
The only solution i found so far
is to wait a long time, about 1 minute
sometimes more, sometimes less.
After this pause the resources seem to
be freed and my program runs without Problem.
(An alternative is to restart the phone.)
I would like to be able to check for free socket ressources.
(I even tried to kill a prozess „com.svox.pico“
which i think is started during socket creation?
but im not sure about this.)
What can i do else?
Can you please give me a little hint about this.
Thank you and best regards
Stephan
This is a good question. I have encountered this also on a linux system. It looks like the port (in your case 5510) gets blocked for a long time. This can happen, when the socket is not closed. e.g. when the program aborts (with an error or even crashes) before the close. Or if the connection gets broken/interrupted. Why it takes so long for the system to detect this, I dont know. If you can always close the socet, then it should not happen and the port would get released.
If you want to write a real searver handling multiple connections, you should probably open the port only once and then handle all connections using FORK. There is an example program for this in the example program collection. See here: https://codeberg.org/kollo/X11-Basic_examples/src/branch/master/All/Internet/TCP/iserver.bas