Sub Service_Start (StartingIntent As Intent)
If MyIP="127.0.0.1" Then
ToastMessageShow("Connessione non disponibile",True)
CallSubDelayed2(Main,"StatoPagina","L-1")
Else
Notify.SetInfo ("QZ service...","...in backgroud...",Main)
Service.StartForeground(1,Notify)
Socket2.Initialize("Socket2")
Socket2.TimeOut=90000
Socket2.Connect(IpSERVER,portServer,gaptimaWaitconnection)
End If
End Sub
Sub Socket2_Connected(Connected As Boolean)As Boolean
If Connected = True Then
AStreams2.Initialize(Socket2.InputStream , Socket2.OutputStream,"Astreams2")
If IsOnLine=False Then
StringaDaInviare="LogIn" & GapChar & CodiceUtente & GapChar & MyIP & GapChar
SendData(StringaDaInviare)
End If
Else
ToastMessageShow("Server not available",True)
Socket2.Close
CallSubDelayed2(Main,"StatoPagina","L-1")
End If
End Sub
Sub AStreams2_NewData(Buffer1() As Byte)
Dim appo As String
Dim msg() As String
Dim cMsg As String
Dim t As String
Dim x As Int
Dim unsignedi As Int
Dim signedb As Byte
appo = BytesToString(Buffer1, 0, Buffer1.Length, "ASCII")
msg=Regex.split(GapChar,appo)
Select Case msg(0).ToUpperCase
Case "LogInOK".ToUpperCase
If CodiceUtente=msg(1) Then
IsOnLine=True
NomeSquadra=msg(2)
stato="Attesa".ToUpperCase
CallSubDelayed2(Main,"StatoPagina","C-0")
CallSubDelayed2(Main,"StatoPagina","A-0")
ToastMessageShow("Connected",True)
End If
Case "LogInDOPPIO".ToUpperCase
AStreams2.Close
Socket2.Close
IsOnLine=False
CallSubDelayed2(Main,"StatoPagina","L-1")
ToastMessageShow("Giàesistente!!!",True)
Case "LogOutOk".ToUpperCase
If CodiceUtente=msg(1) Then
CallSubDelayed(Main,"ChiudiApplicazione")
End If
Case "LogOutDaAdminNoMessage".ToUpperCase
If CodiceUtente=msg(1) Then
CallSubDelayed(Main,"ChiudiApplicazione")
End If
Case "Istruzioni".ToUpperCase
CallSubDelayed2(Main,"StatoPagina","I-0")
stato="Istruzioni".ToUpperCase
Case "Attesa".ToUpperCase
CallSubDelayed2(Main,"StatoPagina","A-0")
stato="Attesa".ToUpperCase
Case "VisualizzazioneVuota".ToUpperCase
CallSubDelayed2(Main,"StatoPagina","V-0")
stato="VisualizzazioneVuota".ToUpperCase
Case "Dm".ToUpperCase
RE=""
If msg(7)="1" Then
RE="A"
End If
If msg(8)="1" Then
RE="B"
End If
If msg(9)="1" Then
RE="C"
End If
If msg(10)="1" Then
RE="D"
End If
If msg(11)="1" Then
RE="E"
End If
ID_p=msg(16)
ID_d=msg(15)
CallSubDelayed2(Main,"StatoPagina","D-0")
stato=msg(17)
Case "Rp".ToUpperCase
CallSubDelayed2(Main,"StatoPagina","R-0")
stato="Rp".ToUpperCase
Case "StopAgnostic".ToUpperCase
CallSubDelayed2(Main,"StatoPagina","S-0")
Case "TriggerSync".ToUpperCase
CallSubDelayed2(Main,"StatoPagina","T-0")
CallSubDelayed2(Main,"StatoPagina","T-1")
Case "Cl".ToUpperCase
If msg(1).ToUpperCase ="CP".ToUpperCase Then
stato="CP".ToUpperCase
CallSubDelayed2(Main,"StatoPagina","CP-0")
End If
If msg(1).ToUpperCase ="CG".ToUpperCase Then
stato="CG".ToUpperCase
CallSubDelayed2(Main,"StatoPagina","CG-0")
End If
Case "QZ".ToUpperCase
stato="QZ".ToUpperCase
CallSubDelayed2(Main,"StatoPagina","Q-0")
Case "NS".ToUpperCase
stato="NS".ToUpperCase
CallSubDelayed2(Main,"StatoPagina","N-0")
Case "CDQZ".ToUpperCase
stato="CDQZ".ToUpperCase
CallSubDelayed2(Main,"StatoPagina","W-0")
End Select
End Sub
Sub SendData(msg As String)
Dim Buffer() As Byte
Buffer = msg.GetBytes("UTF8")
AStreams2.Write(Buffer)
If CloseApp Then
CallSubDelayed(Main,"ChiudiApplicazione")
End If
End Sub
Sub AStreams2_Error
AStreams2.Close
Socket2.close
Socket2.TimeOut=9000000
Socket2.Connect(IpSERVER,portServer,gaptimaWaitconnection)
' ToastMessageShow(LastException.Message ,True)
End Sub
Sub Socket2_Error
AStreams2.Close
Socket2.close
Socket2.TimeOut=9000000
Socket2.Connect(IpSERVER,portServer,gaptimaWaitconnection)
End Sub