Android Question AsyncStreams Incoming Connection

jgbozza

Member
Licensed User
Longtime User
Using network library and AsynStreams, I have an array of sockets, adding the new one to this array every time the Server_NewConnection is fired.
When this new connections sends any data to server, it fires the AStreams_NewData event...so far so good.
How come I get to know which client has sent the data to the server? Is there any sort of async parameter that carries this information ?
 

mc73

Well-Known Member
Licensed User
Longtime User
What I do in such cases is adding an ID of the connected device at the beginning of the message sent.
 
Upvote 0

jgbozza

Member
Licensed User
Longtime User
Is there anywhere to find a little bit of code ? This is the second time you suggest me to use MAP for diferente aplications but I cannot find out how to implement a map in order to keep values of the socket (sender) and track them when the NewData is fired.
Tks

There's no sender attached to sockets or asyncstreams in the example you suggested me.

B4X:
Sub Server_NewConnection (Successful As Boolean, NewSocket As Socket)
    If Successful Then
        If astream.IsInitialized Then astream.Close
        astream.InitializePrefix(NewSocket.InputStream, False, NewSocket.OutputStream, "astream")
        lblStatus.Text = "Status: Connected"
    Else
        Log(LastException)
    End If
    server.Listen
End Sub

Sub astream_NewData (Buffer() As Byte)
    Log("received: " & DateTime.GetSecond(DateTime.Now))
    Dim In As InputStream
    Log(Buffer.Length)
    In.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
    Dim img As Image
    img.Initialize2(In)
    ImageView1.SetImage(img)
End Sub
 
Last edited:
Upvote 0

jgbozza

Member
Licensed User
Longtime User
RandomAccessFile is native right ? I should download the latest version of the IDE ? If so, I have to renew my license! Just let me know please
 
Upvote 0
Top