iOS Question Sample code for sending data from iOS device to server (UTF8)

Discussion in 'iOS Questions' started by dclarkchem, Jan 18, 2018.

  1. dclarkchem

    dclarkchem Member Licensed User

    Have successfully created an app with B4A, but wondering if there is sample code to do this with B4i. Here is part of what we've done with B4A:
    Code:
    Sub Socket1_Connected(Connected As Boolean)As Boolean
        
    If Connected = True Then
            
    ToastMessageShow("Connected",True)
            lblMsg.Text=
    "Connected!"
            Main.AStreams.Initialize(Main.Socket1.InputStream,Main.Socket1.OutputStream,
    "Astreams")
        
    Else
            
    ToastMessageShow("Server not available",True)
            lblMsg.Text=
    "Server not available"
            btnConnect.Text = 
    "Connect"
        
    End If
        btnConnect.Enabled = 
    True
    End Sub
    Sub AStreams_NewData (Buffer() As Byte)
        
    Dim msg As String
        
    Dim cMsg As String
        
    Dim unsignedi As Int
        
    Dim signedb As Byte
     
        msg = 
    BytesToString(Buffer, 0, Buffer.Length, "ASCII")
        
    Log(msg)
        
    For i = 0 To msg.Length -1
            signedb = Buffer(i)
            unsignedi = 
    Bit.AND(0xff, signedb)
            cMsg = cMsg & 
    Chr(unsignedi)
        
    Next
        
    Log(cMsg)
        lblMsg.Text = x & 
    " / " & msg.Length & " - " & msg
     
    End Sub
    Sub SendData(msg As String)
        
    Dim Buffer() As Byte
     
        Buffer = msg.GetBytes(
    "UTF8")
        Main.AStreams.Write(Buffer)
        Main.AStreams.Write(
    Array As Byte(254))
     
    End Sub
    Would appreciate any help, before I spend 3 weeks and then figure out that it can't be done with B4i.[/code]
     
    Last edited: Jan 19, 2018
    spairo likes this.
  2. Erel

    Erel Administrator Staff Member Licensed User

  3. dclarkchem

    dclarkchem Member Licensed User

    Thanks for that link. After spending a couple of days trying to get the serializator to properly work with our project(s), we gave up in frustration. We were about to abandon all hope, but decided to take Erel at his word ("the code works for both B4A and B4i").

    We stripped down our working B4A program (part of it is shown above) to the bare essentials and verified that it still worked. We tried to write the B4i equivalent. There are definitely structural changes that had to be made, but we got it working this morning ! ! !

    OK, we're only half way to first base, but at least we're in the game again.
     
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