B4J Question WiFi problem

Discussion in 'B4J Questions' started by HARRY, Apr 3, 2015.

  1. HARRY

    HARRY Active Member Licensed User

    Hi,

    The environment:

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

    giga Well-Known Member Licensed User

    Can you explain this a little more? Are you trying to connect B4A to a B4J program via wifi?
     
    Peter Simpson likes this.
  3. HARRY

    HARRY Active Member Licensed 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:
    Code:
    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",4000020000)
    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:

    Code:
    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(
    1False'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
     
  4. giga

    giga Well-Known Member Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice