Android Tutorial [B4X] Net library (FTP, SMTP, POP) with Wait For

Discussion in 'Tutorials & Examples' started by Erel, Oct 9, 2017.

  1. Erel

    Erel Administrator Staff Member Licensed User

    Starting from v1.70 of Net, jNet and iNet libraries the asynchronous methods return a 'sender filter' object.
    This object can be passed as the sender filter parameter in a Wait For call.
    This makes it simpler to manage multiple requests.

    For example:
    Code:
    'ftp was previously initialized and its event name was set to ftp:
    'ftp.Initialize("ftp", "your.server", 21, "user", "password")
    Dim sf As Object = ftp.UploadFile(File.DirAssets, "somefile"False"/somefile")
    Wait For (sf) ftp_UploadCompleted (ServerPath As String, Success As Boolean)
    If Success Then
       
    Log("file was uploaded successfully")
    Else
       
    Log("Error uploading file")
    End If
    Multiple subs can wait for the same event. Thanks to the sender filter parameter, each event will be intercepted in the correct wait for call.

    The same technique can be used with all asynchronous methods in the Net library.

    Notes

    - iNet v1.70 will be included in B4i v4.40.
     
  2. Beja

    Beja Expert Licensed User

    This is a great function.. thanks Erel.. I remembered ProComm for DOS with Kermit protocol.. from the old good days.
     
  3. AHilton

    AHilton Active Member Licensed User


    Completely off topic but, I worked on ProComm Plus for Datastorm back in the late 80's - 91.
     
    Last edited: Oct 12, 2017
    avalle and mmieher like this.
  4. Beja

    Beja Expert Licensed User

    May be off topic but definitely not completely.. If you understood I meant in early nighties there was an Android function called Wait For then what can I say.
    The word WaitFor rang and reminded me a similar word. and invoked memories

    WaitFor "User ID"
    Transmit "my ID"
    WaitFor "Password"
    Trasmit "xdsoh68"
    WaitFor "File Name"
    .
    .
    And so on.

    I was writing this script to automate the file transmission process instead of responding to prompts one by one.
    Modem: Hayes
    Media: Phone line.
     
    Last edited: Oct 12, 2017
  5. AHilton

    AHilton Active Member Licensed User

    I meant that *my* comment about working for Datastorm Technologies was off topic. Not yours.
     
    Beja likes this.
  6. Beja

    Beja Expert Licensed User

    Hhhh understand..
    Also this is off topic.. I remember I used Kermit protocol developed by Columbia university.. Other software vendors were using xmodem. When I submitted the first claims file to the insurance company, they asked me to continue using it .. It was way faster than x and y modems..
     
  7. tufanv

    tufanv Expert Licensed User

    this code snippet gives me an error with b4.81 with inet 1.70 :

    Code:
    B4i Version: 4.81
    Parsing code.    (
    0.03s)
    Compiling code.    (
    0.15s)
    Compiling layouts code.    (
    0.01s)
    Compiling debugger engine code.    (
    1.08s)
    Building Xcode project    (
    0.20s)
    Sending data 
    to remote compiler.    Error
    B4i line: 
    223
    Dim sf As Object = ftp.UploadFile(File.DirDocume
    assigning 
    to 'NSObject *__strong' from incompatible type 'void'
    my line 223 is :
    Dim sf As Object = ftp.UploadFile(File.DirDocuments, "tufan.m4a", False, "/files/tufan.m4a")

    I also tried :
    Dim sf As Object = ftp.UploadFile(File.DirDocuments, "tufan.m4a", False, "/files)
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    Are you sure that you updated the Mac files?
     
  9. tufanv

    tufanv Expert Licensed User

    I am using hosted builder secondary.
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    The header file on the builder was not updated. Please try it again.
     
    tufanv likes this.
  11. tufanv

    tufanv Expert Licensed User

    yes it compiles now thanks. Is there any way to see detailed error message because i am getting file upload error but cant find the reason , I have initilazied the ftp with my server username and password.
     
  12. Erel

    Erel Administrator Staff Member Licensed User

    Check Log(LastException)
     
  13. tufanv

    tufanv Expert Licensed User

    this is the result of this:

    Code:
    <B4IExceptionWrapper: Error Domain=caught_exception Code=0 "Error writing to stream: Error Domain=kCFErrorDomainCFNetwork Code=200 "(null)" UserInfo={kCFFTPStatusCodeKey=500, _kCFStreamErrorCodeKey=500, _kCFStreamErrorDomainKey=6}" UserInfo={NSLocalizedDescription=Error writing to stream: Error Domain=kCFErrorDomainCFNetwork Code=200 "(null)" UserInfo={kCFFTPStatusCodeKey=500, _kCFStreamErrorCodeKey=500, _kCFStreamErrorDomainKey=6}}>
     
  14. Erel

    Erel Administrator Staff Member Licensed User

    It is better if you start a new thread in B4i forum.
     
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