iOS Question Socket prefixmode

wl

Well-Known Member
Licensed User
Hi,

I need to communicate between my IOS add and a B4J server using the least amount of bytes: this is why I'm using sockets instead of HTTP requests.

This is what my server has (A B4J console app with StartMessageLoop):
B4X:
private Sub ListenForSocketConnections
    socketsrvr.Initialize(1973, "serversocket")
    socketsrvr.Listen
    Wait for serversocket_NewConnection (Successful As Boolean, NewSocket As Socket)
    If Successful Then
        If astreams.IsInitialized Then
            astreams.Close   
        End If
        astreams.InitializePrefix(NewSocket.InputStream, True, NewSocket.OutputStream, "astreams")
    End If
End Sub

private Sub astreams_NewData (Buffer() As Byte)   
End Sub

This is what the IOS app has:
B4X:
    Dim sck As Socket
    sck.Initialize("socket")
    sck.Connect("192.168.1.59", 1973, 0)
    wait for socket_Connected (Successful As Boolean)
    If Successful Then
        astreams.InitializePrefix(sck.InputStream, True, sck.OutputStream, "astreams")

        Dim dt As DataTransfert
        dt.Initialize
        Dim data() As Byte = dt.UploadDataToByteArray(id, latitude, longitude, GetBatteryLevel)
        astreams.Write(data)
    End If

The connection is being made Succesfully, but I can't seem to get into the astreams_NewData of the server, whatever I try. What am I missing ?
 

wl

Well-Known Member
Licensed User
Thanks Erel,

I already looked at it, but can't seem to find the issue. Perhaps because I'm running the B4J server app as a console application (something to do with the messageloop or so) ?
 
Upvote 0

wl

Well-Known Member
Licensed User
Damn, I looked over the loop to start to listen in the server ...

B4X:
private Sub ListenForSocketConnections
    Do While True 'THIS !!
        socketsrvr.Listen
        Wait for serversocket_NewConnection (Successful As Boolean, NewSocket As Socket)
        If Successful Then
            If astreams.IsInitialized Then
                astreams.Close
            End If
            astreams.InitializePrefix(NewSocket.InputStream, True, NewSocket.OutputStream, "astreams")
        End If
    Loop
End Sub
 
Upvote 0
Top