B4J Question WebSocket B4J server with B4A client

Discussion in 'B4J Questions' started by GiovanniPolese, Aug 18, 2015.

  1. GiovanniPolese

    GiovanniPolese Active Member Licensed User

    Hi
    posting here the question, but it can be also related to B4A forum.
    I am trying to make an Exchange of messages between a WebSocket server with B4j and a B4A client. The server is a computer in a local network, and the client must be outside it.
    I am using nothing else than the very basic example: B4A - WebSocket.b4j and WebSocketExample in B4A. The only part that I understand to be modifiable is the Ip Address in the B4A Main module code, namely the : Private link as string = "ws://localhost:51042/ws". I used port 47624. In B4J code, the port is also set to 47624. The issue concerns the Ip to substitute to localhost, in the case that the server is inside a local network, and I want to connect from a client outside the local network. First thing should be to get the Ip of my local router and then set a port forwarding, on a computer of the local network. This is exactly what I did, entering the router configuration, getting its Ip (for example 100.67.84.66), then adding to the local machine 192.168.1.10 a port forwarding on port 47624. Finally I went to the Windows control panel and allowed communication on port 47624 (either input or output). Then I set the link in the B4A module to "ws://100.67.84.66:47624/ws" and run the two programs that worked properly, inside my local network. I thought that things were done. As a matter of fact, notice that I didn't use the local network IpAddress, but the global one + port forwarding on the router. Port forwarding also seems to be properly set, because if I, for example, change its number in the B4A code, no communication arises. Then I tried the final test, sending the Android client apk to a friend, and asking him to install and run it on his smartphone. (Of course the server was running on my computer, in the meanwhile). Results are negative: The client was not able to connect, reporting the following error "failed to connect to 100.67.84.66 port 47624 after 30000 ms". So, I don't know what to do. Any ideas? Thanks in advance.. (code attached)
     

    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

  3. GiovanniPolese

    GiovanniPolese Active Member Licensed User

    Sorry, I already did it.
     
  4. GiovanniPolese

    GiovanniPolese Active Member Licensed User

    I know my global IpAddress. DuckDns is a successive step.
     
  5. derez

    derez Expert Licensed User

    What you did seams OK. You can test by your own b4a device with wifi off.
    You can also try the link from a browser in the device in case the problem is in the application.
     
  6. GiovanniPolese

    GiovanniPolese Active Member Licensed User

    Yes, I know, but I have no Internet card in the smartphone, that's why I asked to somebody else to do the test.
     
  7. GiovanniPolese

    GiovanniPolese Active Member Licensed User

    I will try temporarily totally disabling Firewall, so taking away this variable of the problem..
     
  8. GiovanniPolese

    GiovanniPolese Active Member Licensed User

    By the way, I connected now. The B4A code that I posted can be run and tested, if somebody is interested in.
     
  9. GiovanniPolese

    GiovanniPolese Active Member Licensed User

    I totally disabled my firewall, so failure should not depend on it.
     
  10. giga

    giga Well-Known Member Licensed User

    "totally disabled my firewall" What firewall program?
    You can check the service/port fowarding with www.canyouseeme.org on port 47624
     
  11. GiovanniPolese

    GiovanniPolese Active Member Licensed User

    Thanks. Useful hint, but it automatically detects the ip of the provider (just like What is my Ip) and doesn't allow to modify it (if I seee well).. So I cannot test my port. My Ip (now) is 100.67.xx.yy while that utility displays another one. (The provider's one, as I said). Thanks anyway for your attention.
     
  12. GiovanniPolese

    GiovanniPolese Active Member Licensed User

    I don't think it is a Firewall issue. As a matter of fact programs work if tested inside the local network. The Firewall applies to each machine, so it should block communication anyway.
     
  13. LucaMs

    LucaMs Expert Licensed User


    Try this site: http://ping.eu/port-chk/
     
  14. LucaMs

    LucaMs Expert Licensed User

    I tested your b4j server (only) and it works.

    I think that port forwarding is wrong.
    Perhaps the IP address of your PC is dynamic and therefore the association IP / Port you set "is no longer valid".

    If you want, you can specify the router model and your settings.
     
  15. giga

    giga Well-Known Member Licensed User

    What kind of modem are you using? (reason for asking some ISP's may block ports)
    Is it a modem/router? (reason for asking some modem/routers have to be in bridge-mode if you have another router behind it to manage ports.)

    Your WAN IP should be what you are pointing to from the outside world.
    (ideally should be static IP, if it is dynamic IP use a DuckDns IP to forward to your changing IP.
    Port Forwarding to your PC in the LAN from the router(What ever has the server)

    With the server running use www.canyouseeme.org to check the port
    or as @LucaMs said
    Try this site: http://ping.eu/port-chk/
     
  16. GiovanniPolese

    GiovanniPolese Active Member Licensed User

    Hi, sorry for delay in answering (and for writing in English with italians).
    LucaMs: What do you mean with testing my b4j server and works? The problem is testing both B4j server and B4A client. Can you explain better what you mean? The actual help should be to see whether the B4A client connects. I have seen in the forum that you successfully tested a similar configuration and I also consider this a fixed point.
    My problem is not to have an external connection to test myself this situation, but, anyway, it is rather clear that this combination B4J+B4A, as is, doesn't work in my conditions. It could be the router, as giga said, but let's point out one thing: forget about the fact that the public Ip of my router is dynamic, this is not the concern. I know this, and, exactly for this reason, before doing any experiment, I verify which is the actual public Ip of the router. It changes every day, because I shut it down at night. Of course I modify the Ip strings in the software and make the proper port forwarding in the router setup. Also I check the Windows Firewall or even disable it.
    If you are interested, we can make the following: I post now the settings of my router, so anybody who has better knowledge of the situation can soggest something. I will also modify the B4x modules according to these settings (public Ip and port), and post them here too. I will also leave the server active all the day. If anybody is able to connect we resolve the issue. Otherwise, at least with Netgear router (or something involving it) the problem exists.
    Attached: ipconfig of the local machine, router screen-shots, firewall ports setting, local successfull test, modified modules with actual server Ip and port.
    Thanks a lot for your cooperation and forgive my ignorance...
     

    Attached Files:

  17. GiovanniPolese

    GiovanniPolese Active Member Licensed User

    By the way I verified with your links that the port is closed. Then all this needs much more expertise than normal. ...
     
  18. GiovanniPolese

    GiovanniPolese Active Member Licensed User

    Finally, resulting the port closed, every test with the software is clearly useless, so thanks to everybody and forget about. The problem must be elsewhere. These posts may serve as experience for somebody else. Things aren't so simple. probably it is necessary to examine the router in detail..
     
  19. GiovanniPolese

    GiovanniPolese Active Member Licensed User

    To complete the discouraging picture, I post also another page of the router setup where something "suspicious" (I am not expert of these topics) appears, regarding WAN setup. Also with the attached setup, that seems to give more chances for external connections, port remains closed. (But is could be that this means nothing, as seems to be).
     

    Attached Files:

  20. LucaMs

    LucaMs Expert Licensed User

    (do not forget the italian forum exists, if you want write in italian... as I prefer, of course, given that my english is... no comment :D).

    First of all, I think you should test the "project" with ALL firewalls disabled (except for the router firewall).

    As I wrote, you should ensure that the port mapping you set is "still valid".

    I mean: you restart your router everyday; then, you public (WAN) IP changes, but your PC IP? Too? IPConfig today shows your IP = 192.168.1.4, but yesterday?
    How is set the port forwarding? Something like: "open port 51042 and "link" it to 192.168.1.2 because this was my PC IP yesterday?

    I suspect this; everyday the public IP changes, you PC IP changes but the port forwarding is fixed!

    Now I have few minutes, but I'll search documentations of your router. Please, post the model and its web page where you set the port forwarding.

    E nel forum italiano ci capiremmo meglio (benché nelle immagini io vedo lo spagnolo :eek::))
     
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