B4J Question WebSocket B4J server with B4A client

GiovanniPolese

Well-Known Member
Licensed User
Longtime 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)
 

Attachments

  • WebSocketExample.zip
    414.1 KB · Views: 375
  • B4A-WebSocket.zip
    21.6 KB · Views: 313

derez

Expert
Licensed User
Longtime 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.
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime 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.
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime 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.
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime 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.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime 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.
 
Upvote 0

giga

Well-Known Member
Licensed User
Longtime 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/
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime 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...
 

Attachments

  • B4A-WebSocket_B4J.zip
    9.2 KB · Views: 252
  • WebSocketExample_B4A.zip
    412.8 KB · Views: 228
  • router_0-1.zip
    386 KB · Views: 252
  • router_2-3.zip
    300.6 KB · Views: 259
  • IpConfig.png
    IpConfig.png
    54.4 KB · Views: 280
  • local_test.png
    local_test.png
    107.9 KB · Views: 274
  • firewall_enter_port.png
    firewall_enter_port.png
    251.8 KB · Views: 294
  • firewall_exit_port.png
    firewall_exit_port.png
    253.4 KB · Views: 258
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
By the way I verified with your links that the port is closed. Then all this needs much more expertise than normal. ...
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime 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..
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime 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).
 

Attachments

  • router_4.png
    router_4.png
    176.7 KB · Views: 268
Upvote 0

LucaMs

Expert
Licensed User
Longtime 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::))
 
Upvote 0
Top