B4R Question "error" log in B4R Astreams Client/ Server Tutorial

Discussion in 'B4R Questions' started by RJB, Aug 12, 2019.

  1. RJB

    RJB Active Member Licensed User

    Continued from https://www.b4x.com/android/forum/threads/b4r-sockets-astreams-initialize-errors-8266-wifi.108381/
    regarding tutorial https://www.b4x.com/android/forum/threads/connecting-two-esp8266-boards.89726/#content

    I've re- read and re-tested the code from the tutorial as suggested, and again get the same result. i.e. as given in the tutorial.
    I still don't understand why Astream_error is called each time.
    Perhaps I am just being blind or stupid but could you please explain why?
    Thanks

    Server:
    Code:
    1
    192.168.4.1
    192.168.4.1
    0.0.0.0
    new connection
    new data: hello!!!
    error                    <----------------
    new connection
    new data: hello!!!
    error                    <----------------
    new connection
    new data: hello!!!
    error                    <----------------
    Client:
    Code:
    1
    192.168.4.2
    Trying 
    to connect
    connected
    error     <---------------
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    AStream_Error is called when the connection is broken. As written in the tutorial the server code closes the connection after it receives the message. Once it closes the connection the error events are raised.
     
  3. RJB

    RJB Active Member Licensed User

    OK thanks, that then raises it at both ends?
    Is that the only condition which calls "_error"? If not is there any way of telling what has called it?
    Otherwise it looks like we just have to ignore "_error"?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Error event will be raised whenever the connection breaks. There isn't any other information.

    Depends on your requirements.
     
  5. RJB

    RJB Active Member Licensed User

    OK thanks very much.
    I'd like to put a link to this on the original thread, but it seems to be closed. It's always frustrating when a new one is started but you can't find it. Are you able to put the link on it?
    Thanks
     
  6. KMatle

    KMatle Expert Licensed User

    Never had this issue. Are you sure you don't disconnect it yourself or your router?
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    On the contrary. He is using this code which disconnects the connection by design: Connecting two ESP8266 boards
     
  8. RJB

    RJB Active Member Licensed User

    As far as I can see with this code the Server is set up and listening.
    There is a new connection from the client and the socket/ Astream are set up.
    Data is received and the socket is closed.
    The error is raised and server.listen is called again.
    A new connection is made from the client.
    etc.
    All I didn't understand was why the error was raised. Erel has explained that it is raised when you close the socket.
    Seems strange but if that's the way it works then that's what we have to work with.
     
  9. RJB

    RJB Active Member Licensed User

    The other thread appears to be open again now so I have added a link to this one.
     
  10. RJB

    RJB Active Member Licensed User

    Further information:
    I assumed from the above that removing the .close statement would leave the connection in tact, which it does. But I also assumed that in that state removing the power from the device at one end would break the connection and produce an error at the other.
    Removing the power at the server end does, indeed, produce an error at the client end.
    But, removing the power at the client end doesn't give any error at the server end, even after many minutes. Further on re-connecting the power at the client end, the client tries to connect and write and, apparently, succeeds but nothing happens at the server end.
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    You should start a new thread for a new question.
     
  12. RJB

    RJB Active Member Licensed User

Loading...
  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