Android Question [Solved] Astream or Socket Problem

Discussion in 'Android Questions' started by hogiebaer, Jun 8, 2015.

  1. hogiebaer

    hogiebaer Active Member Licensed User

    Hi Devs,

    I have a big problem with AStreams or Sockets.
    When printing on a receipt printer over port 9100 i use


    sub socket1_Connected (Successful As Boolean)
    if successful=true then
    end if
    end sub
    This code works. Most of the time. But sometimes the Astream.Write doesnt finish, or doesnt get started at all before the Astream.Close event happens, or the socket close.

    If i don´t close the stream/socket it works, but i have to close the stream/socket, because the printer
    can´t reach from another station, if the connection is online !!

    What can i do ????


    Use b4a 4.30, network(1.25), randomaccessfile(2.00)
    Last edited: Jun 8, 2015
  2. hogiebaer

    hogiebaer Active Member Licensed User

    Ok, i have a dirty solution

    Do While astream.OutputQueueSize<>0
    but it could be very dangerous, i hate "doevents"

    other solutions ?
    Last edited: Jun 8, 2015
  3. Erel

    Erel Administrator Staff Member Licensed User

    Does the printer return any response when it is done printing? If not then you should use a timer instead of the Do While loop.
  4. hogiebaer

    hogiebaer Active Member Licensed User

    Hi Erel, no response, the only "error" is for me the "connected=false" or "astream events".
    The way over a timer is a good idea.

    i could start a timer after write (100msec)

    sub checkclose_tick
    if astream.outputqueuesize<>0 then return
    end sub
    Erel likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice