Connect Basic4Android app to Basic4PPC app to send text via TCP

synasir

Member
Licensed User
Longtime User
Using the ChitChat.zip (WM) example and TestTcpIp.zip (Android) example.

The WM app is running as server and the Android app is running as client.

The Android app can connect to the WM app but when data is sent from the Android app, the WM app hung up

Basic4PPC coding
B4X:
Sub tmrWaitForData_Tick 'Checks the DataAvailable property. If data is available then it reads it.
'The server sends the data to all other clients.
   If blnServer = False Then 'client
      If Client.DataAvailable = True Then
         s = stream.ReadString 'Reads the string from the stream.
         txtReceive.Text = txtReceive.Text & CRLF & s
         txtReceive.SelectionStart = StrLength(txtReceive.Text)-1
         txtReceive.ScrollToCaret
         If blnSound = True Then Sound("notify.wav")
      End If
   Else 'server
      i = 0
      Do While i < alClients.Count 'The server checks the data of all clients.
         t = alClients.Item(i)
         If Control("client" & t,Client).DataAvailable = True Then
            s = Control("stream" & t,Binaryfile).ReadString
            txtReceive.Text = txtReceive.Text & CRLF & s
            txtReceive.SelectionStart = StrLength(txtReceive.Text)-1
            txtReceive.ScrollToCaret
            SendToAllClients(s,t) 'The server sends the data to all clients except of the client who sent the data.
            If blnSound = True Then Sound("notify.wav")
         End If
         i = i + 1
      Loop
   End If   
End Sub

Android coding
B4X:
Sub Socket1_Connected(Connected As Boolean)As Boolean 
   If Connected = True Then
      AStreams.Initialize(Socket1.InputStream,Socket1.OutputStream,"Astreams")
   Else
      ToastMessageShow("Server not available",True)      
      btnConnect.Text = "Connect"
   End If
   btnConnect.Enabled = True
End Sub


Sub SendData(msg As String)
   Dim Buffer() As Byte 
   
   Buffer = msg.GetBytes("UTF8")
   AStreams.Write(Buffer)
   AStreams.Write(Array As Byte(254))
   
End Sub

Changing UTF8 to ASCII also does not work.
Using TextWriter also does not work.

Thanks.
 

synasir

Member
Licensed User
Longtime User
So how do I over come this problem? If possible I do not want to change the Basic4PPC coding as I have other Basic4PPC clients connecting to the server. How can I get the Android to just send and receive regular string. Thanks.
 
Upvote 0
Top