B4J Question WiFi problem

HARRY

Active Member
Licensed User
Longtime User
Hi,

The environment:

On my smartphone a B4A program is running in debug mode using the B4Abridge
 

HARRY

Active Member
Licensed User
Longtime User
Sorry,

The initial text was far from complete. Once again:

The environment:

On my smartphone a B4A program is running in debug mode using the B4ABridge, on my Raspberry a B4J program is running also in debug mode using B4JBridge.
The smartphone tries to establish a connection with the Raspberry.

In most cases, practically always, the B4A program reports that the connection is made successfully, however in the B4J program no new connection is reported.

Parts of the code is:

On the B4A side:
B4X:
Dim AStream As AsyncStreamsText
Dim Client As Socket

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Main")
    Client.Initialize("Client")
End sub       

Sub CBConnect_Click
    If Client.IsInitialized=False Then Client.Initialize("Client")
        Client.Connect("192.168.2.7",40000, 20000)
End Sub

Sub Client_Connected (Successful As Boolean)
    If Successful Then
        If AStream.IsInitialized Then AStream.Close
        ToastMessageShow("Connected", False)
        AStream.Initialize(Me,"AStream",Client.InputStream,Client.OutputStream)
        TBReceive.text="Verbinding tot stand gebracht"
        EnDisable(True)
    Else
        ToastMessageShow(LastException.Message, True)
    End If
End Sub

Public Sub Send (Mess As String)
    If Client.Connected=False Then
        CBConnect_Click
    End If
    If AStream.IsInitialized = False Then AStream.Initialize(Me,"AStream",Client.InputStream,Client.OutputStream)
    P1.Enabled=False
    AStream.Write(Mess&CRLF)
End Sub

On the B4J side:

B4X:
Dim BStream As AsyncStreamsText
Dim server As ServerSocket

Sub AppStart (Args() As String)
Dim i As Int
    sp.initialize("AStream")
    Log(sp.ListPorts)
    sp.Open("/dev/ttyUSB0")
    sp.SetParams(9600,8,1,0)
    For    i=0 To 23
        table(i).Initialize
    Next
    AStream.Initialize(Me, "AStream",sp.GetInputStream,sp.GetOutputStream)
    server.Initialize(40000,"server")
    server.listen
    DateTime.DateFormat="dd MMM yy "
    DateTime.TimeFormat="HH 'uur' mm 'min' ss 'sec'"
    controller.Initialize
    Pin1.Initialize(1, False) 'GpioPinDigitalOutput
    StartMessageLoop
End Sub

Sub server_NewConnection (Successful As Boolean, NewSocket As Socket)  'internet
    If Successful Then     
        BStream.Initialize(Me, "BStream",NewSocket.InputStream, NewSocket.OutputStream)
    Else
        Log (LastException.Message)
    End If
    server.Listen
End Sub
Sub BStream_NewText(Text As String)
Dim reply As String
    Pin1.Pulse(300)
    If Text= "1" Then
        reply=elecconsumption & cr
        BStream.Write(reply)
End sub

There is also an AStream in the B4J program that reads from an USB port; that part works very well. When I run the B4J program in Release mode there is no change in behaviour.

Does somebody have any idea why the established connection is not reported in teh B4J program?

Harry

Harry
 
Upvote 0

giga

Well-Known Member
Licensed User
Longtime User
Upvote 0
Top