French données texte entre PHP et B4A

herve joly

New Member
Licensed User
Bonjour,
Je voudrais pouvoir envoyer de mon serveur (via PHP) des données au format texte vers B4a
Du coté B4A j'initialise un server qui ecoute un port , par contre coté PHP je ne sais pas trop comment faire, j'arrive bien à me connecter entre mon serveur php et mon android , cote PHP j'envois du texte mais j'ai une erreur (Astream_error)
y a t'il un petit exemple de script PHP pour envoyer des données ?

Merci
Hervé


Starter :
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private Astream As AsyncStreams
    Private Server As ServerSocket
    Public IsConnected As Boolean
End Sub

Sub Service_Create
    'This is the program entry point.
    'This is a good place to load resources that are not specific to a single activity.
    ListenForConnections
End Sub

Sub Service_Start (StartingIntent As Intent)

End Sub

Sub Service_TaskRemoved
    'This event will be raised when the user removes the app from the recent apps list.
End Sub

'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub Service_Destroy

End Sub

private Sub ListenForConnections
    Server.Initialize(51042,"server")
    Log($"My ip is : "${Server.GetMyWifiIP}"$)
    Server.Listen
    wait for server_newconnection(succeful As Boolean,newsocket As Socket)
    Log("new connection")
    
    If succeful Then
        
        If Astream.IsInitialized Then
            
            Astream.Close
        End If
        Astream.InitializePrefix(newsocket.InputStream,False,newsocket.OutputStream,"Astream")
        SetState(True)
    End If
End Sub

private Sub SetState  (connected As Boolean)
    IsConnected=connected
    CallSub(Main,"StateChanged")
End Sub
private Sub Astream_terminated
    Log("AStreams_Terminated")
End Sub
Sub Astream_NewData (Buffer() As Byte)
    Log("new data")
    Dim msg As String
    msg = BytesToString(Buffer, 0,Buffer.Length, "UTF8")
    Log(msg)
End Sub

private Sub Astream_error
    Log("AStream_Error")
    Astream_terminated
    
End Sub

main :
B4X:
Sub Process_Globals

    
End Sub

Sub Globals
    
    Private lblstate As Label
End Sub

Public Sub StateChanged
    If Starter.IsConnected Then
        lblstate.Text ="State : Connected"
    Else
        lblstate.Text= "State : Disconnected"
    End If
End Sub

Sub Activity_Resume
    StateChanged
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("l1")
    
End Sub



Sub Activity_Pause(UserClosed As Boolean)
    
End Sub
 
Top