Android Question WAN access from BvA to B4j program

Discussion in 'Android Questions' started by HARRY, Apr 19, 2015.

  1. HARRY

    HARRY Active Member Licensed User

    Hi,

    On my Raspberry runs a b4J program (server application) that listens to port 40000.

    On my smartphone runs a b4a program that should connect to the Raspberry:

    a) using the LAN address of the Raspberry and the port number 40000, that works perfectly.

    b) using the WAN IP address of my internet connection and port 40000. Whatever I try, no connection is established.

    The two programs exchange simple text strings, no command or whatoever.

    On my router I have defined port forwarding for port 40000 to the LAN address of the Raspberry.

    Checking it from the outside, the port indeed is open.

    On internet I read a lot about SSH:

    Do I need it? There is no security issue about the data exchanged.

    It seems to be enabled by default on te raspberry.

    If one side is using SSH , should the other side then use it as well?

    I think other programs are using SSH, like Win SCP. Disabling SSH on the Raspberry would be inconvenient, but acceptable.

    If neccessary, how to combine SSH with b4A?

    Or does another reason prevent connection, not related to SSH

    Who can show me the direction to go?

    Harry
     
    Last edited: Apr 19, 2015
  2. giga

    giga Well-Known Member Licensed User

  3. HARRY

    HARRY Active Member Licensed User

    Hi giga,

    "Yes if that is what the port is expecting". Do you mean with 'the port' port 40000? I got the impression that SSH uses another port.

    Anyway, for testing purposes I disabled SSH in the Raspberry and did a Reboot. No changes, still no connection from my smart phone.
    Should my simple setup work? Below the relevant code from both programs:

    On the A4J side:
    Code:
    Dim Client As Socket
    Client.Initialize(
    "Client")
    Client.Connect(
    "my public IP address",40000,20000)
    Sub Client_Connected (Successful As Boolean)
        
    If Successful Then
            
    If AStream.IsInitialized Then AStream.Close
            
    ToastMessageShow("Connected"True)
            AStream.Initialize(Me,
    "AStream",Client.InputStream,Client.OutputStream)

    etc.
    On the b4J side:
    Code:
    Dim server As ServerSocket
    server.Initialize(40000,"server")
        
    server.listen
    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
    Note that on the LAN everything works fine, even when WiFi is enabled and I use the external internet address i.s.o the LAN address.

    Do you have more wisdom?

    Harry
     
  4. Erel

    Erel Administrator Staff Member Licensed User

  5. giga

    giga Well-Known Member Licensed User

    Default port for SSH is 22. Although you can customize any port to have SSH. I see no issue with your code. If you are able to get into the PI in the LAN but not through the WAN I would check the port 40000 access from the outside world.
    You could use www.canyouseeme.org if the result is "Error" on that port I would check the router forwarding.

    Remember across LAN access to the port 40000 is not managed by the router unless you have a higher end router.
     
  6. HARRY

    HARRY Active Member Licensed User

    Thanks Erel,

    I will try what you suggested. However, this will take some time as I have problems with port forwarding on my router. Possibly I will need another one.

    Harry
     
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