Android Question UDP_PacketArrived get no data when use msgbox

shugeyi

Member
Licensed User
hi, all :
my code is here:
B4X:
Sub Process_Globals
   
    Public FirstTime As Boolean=True
    Public UDPSocket1 As UDPSocket
    Public m_CheckIP As String
    Public m_CheckPort As String
   
End Sub

Sub Service_Create
    If FirstTime = True Then
      
        m_CheckIP="192.168.1.20"
        m_CheckPort=1200
        UDPSocket1.Initialize("UDP", 1200, 5000)
    End If

    FirstTime = False
 
   
End Sub

Sub Service_Start (StartingIntent As Intent)

    ReadForce
    Log("readforce")
    StartServiceAt(Me,DateTime.Now+100,True)
End Sub

Sub Service_Destroy

End Sub

Private Sub WriteString(strWrite As String)
    Dim Packet As UDPPacket
    Dim Data() As Byte
    Dim strCmd As String=strWrite
    Data = strCmd.GetBytes("UTF8")
    Packet.Initialize(Data, m_CheckIP, m_CheckPort)
    UDPSocket1.Send(Packet)
   
End Sub


Sub ReadForce
    'm_SendForceTime=DateTime.Now
    Dim strCmd As String="#GT" & Chr(13)
    WriteString(strCmd)
End Sub

Sub UDP_PacketArrived (Packet As UDPPacket)
    Dim msg As String
    msg = BytesToString(Packet.Data, Packet.Offset, Packet.Length,"UTF8")
    Log("getdata:" & DateTime.Now & ":" & msg)
   
End Sub
so far so good,but ,when i show a msgbox in my activity ,UDP_PacketArrived not work,no data arrived.
log is show
readforce
getdata:.....
readforce
getdata:.....

when msgbox show:
readforce
readforce
readforce

when msgbox close:
getdata
getdata
getdata
readforce
getdata
readforce
getdata
readforce
getdata


i don't want the data be interupt ,who can help me, thanks
 

shugeyi

Member
Licensed User
Then you should not block the main-thread with a msgbox.
Use LOG-Statements instead or a non blocking alternative to msgbox
but my udp is not in main thread ,it's in server, and when msgbox show ,server is still run ,
just UDP_PacketArrived no data arrived . is there other way to solve this problem?
 

aidymp

Active Member
Licensed User
Then you should not block the main-thread with a msgbox.
Use LOG-Statements instead or a non blocking alternative to msgbox
Hi, What alternative is there to a message box that does not block the main thread? is there a way to display a messagebox that does not stop everything?? or maybe an alternate library to display a message but still run the code?
 

RandomCoder

Well-Known Member
Licensed User
You could try a toastmessage as an alternative.
 

shugeyi

Member
Licensed User
it's very trouble, i can not use messagebox , also i can not use dialog libs ,all of this i have to write by myself ,it's very trouble.............
 
Top