Menu

How can i check if resources for tcp-connection are free?

Android
2021-03-02
2021-03-03
  • salue salue

    salue salue - 2021-03-02

    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.

    ---------------- the prog -------------------------------

    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


    This all works fine.

    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:



    ON ERROR GOTO weiter
    weiter:
    OPEN "US",#Listener 1,"",5510


    But same error message.

    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

     
  • Markus Hoffmann

    Markus Hoffmann - 2021-03-03

    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

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.