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

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
LucaMs: I will write in the italian fórum now.
This is to avoid any misunderstanding to readers: I know that either router or local Ip change (daily the router, and at every restart of local machines the local). I coherently managed it, as screen shots report. The pictures are on a portuguêse laptop (I work mainly in Portugal, but I am in Italy now), but I guess this is not the concern. Thanks
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
1) Verifica l'indirizzo IP attuale del tuo PC, usando IPConfig
2) verifica che la porta sia "collegata" al IP del tuo PC (il mapping / port forwarding nella pagina web del router)
3) vai su http://ping.eu/port-chk/ fai click sull'IP (che corrisponde all'indirizzo pubblico del tuo router); esso sarà copiato in basso, dove metterai il numero della porta and Go per vedere se la porta risulta aperta (ovviamente con il server b4j avviato, altrimenti risulterà chiusa comunque)
 
Upvote 0

giga

Well-Known Member
Licensed User
Longtime User
All respect, I don't speak/read Italian.
There are a couple of things to check.
1. In my opinion I would "uncheck" DMZ (this opens 192.168.1.4 to the world for attacks)
2. Update the firmware on the router.you have V1.2.30_41.0.44 and there are 2 newer versions (US) "BACKUP YOUR SETTINGS FIRST"
3. You are using dynamic IP on the WAN so check the port after the firmware update with one of the port testers again and DMZ off (make sure your WAN IP does not change if it does adjust your app or DuckDNS .

http://downloadcenter.netgear.com/en/product/WGR614v9#searchResults

Netgears notes on DMZ:
http://kb.netgear.com/app/answers/detail/a_id/25891/~/dmz-on-netgear-routers

Good Luck.
 
Last edited:
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Hi, sorry for going to Italian fórum. It was just because with LucaMs understanding should be easier. As a matter of fact, with him, we didn't resolve my problema, though we we were able to fix that the problem is in my router. So, before abandoning the issue, I will follow your indications. I will point out some facts. First of all I let you know that my router has a search for updates, just when it starts, and, regularly, says that nothing new update is available. This update operation could be riskful, because I am all but an expert on this topic. I would prefer not to make any udpate, in these conditions. About the other facts, I observed that, even without restarting the router, the Ip changes. This happened today, for example. But I was carefully checking this fact and I can exclude any change of router public Ip, during my tests. There is a notable thing, emerged during my tests with LucaMs: when I use the "http--ping.eu-port-chk-", on the top of the window appears "my Ip", but this is nothing else that same address reported by WhatIsMyIp, namely the Ip of my Internet provider. This is not my router's Ip. With LucaMs, we reverted our positions and he opened the port and run the server, allowing me to connect. It worked. He showed his window of the http--ping and it reports on the top the same address of his router. I attach the two screens, so you can understand what I mean: for him the top Ip is the same that we must input in the ping while in mine not. Thanks for your attention. Unluckily I am not so expert of these topics, so further instructions can be useless, because I cannot apply them with safety. One thing should be interesting for me: be sure that with you things work, like I did with LucaMs. So, if you can see what happens with your router, and whether the ping reports same address on the top, it can be interesting. As a matter of fact this the only evident difference with LucaMs. Thanks again.
 

Attachments

  • LucaMs_computer.png
    LucaMs_computer.png
    154.1 KB · Views: 247
  • my_computer.png
    my_computer.png
    118.6 KB · Views: 293
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Giovanni, you set that IP in "IP address or host name" (100...). You should, instead, just click on "Your IP is 212...". 212... is your WAN IP, the IP your ISP assigned to your router.

I suppose that 100.... is an IP of your local network, the IP of your PC.

upload_2015-8-19_14-13-57-png.36788


You should click on "Your IP is 212..."; it will be copied below, "IP address or host name". This way it should work.


BEFORE, you should:
upload_2015-8-19_13-45-50-png.36784


Server IP Addres should be the IP of your PC (see it using IPConfig).

Then:
upload_2015-8-19_13-50-2-png.36785
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
LucaMs, I will try again, but I already did this test, as documented by the attached screen-shot, that I sent you in the italian forum. In this case, I wrote in the input field, the value displayed on the top of the window. Result is negative, as always... But, as I said, I will give it a new try. Thanks again for your support.
 

Attachments

  • risultato_scorretto.png
    risultato_scorretto.png
    113.6 KB · Views: 272
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
LucaMs, I will try again, but I already did this test, as documented by the attached screen-shot, that I sent you in the italian forum. In this case, I wrote in the input field, the value displayed on the top of the window. Result is negative, as always... But, as I said, I will give it a new try. Thanks again for your support.

This is the right test (you don't need to enter the IP, just click on "Your ip is" IP).

You should set well the port forwarding, this is the question.
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Ok. I did everything. I understood that clicking on the top Ip it will be used as input. Did port forwarding, Firewall disabled... Nevertheless ... port closed.. I always think to Erel's sentence "Eventually you will get it working" (in a post on this topic). Perhaps some thin humour in that sentence... Thanks again. Bye.
 
Upvote 0

giga

Well-Known Member
Licensed User
Longtime User
The top IP in the picture is the correct IP. That is your WAN(Wide Area Network) IP given to you by your provider(ISP). With that number and port forwarding setup on your router you should be able to see in your network on that port 51042.

Firmware.
Even if the router has a "check for firmware update" button I would check the installed versions vs. what's online for this model.
I have installed 100's of routers and I still check manually because if the firmware is bad and affect that part of their code." It may not connect to the manufacturer to update it."

I understand if you don't feel comfortable with updating the firmware. You could contact Netgear support and they can assist you on how to.

What is you modem model?
You have a Netgear router but we need the modem info too.

I suspect your modem as I mentioned earlier.
 
Last edited:
Upvote 0

giga

Well-Known Member
Licensed User
Longtime User
The wgr614v9 is a router not a modem.

What is the Netgear wgr614v9 connected to on the WAN port? (YELLOW Port in the picture)
Based off his pictures he is establishing PPPOE connection through something (router_0.png)
I believe his ISP is ngi.it which should use a modem



My point with this is:
The modem has to be in bridge-mode which allows the router to handle ALL traffic and port forwarding.
 
Last edited:
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Dear Friends, I must apologize for this story. It is not my fault, of course, but the simplest thing didn't come out quickly. Thanks to Giga question on modem, I decided to call my provider. As soon as I exposed my story, they naively told me that, by default, their clients Ips are not public. So, all our efforts will never have success. Then they offered me to change my Ip to public and I already tested that everything works... It was very simple... "Eventually we got it working". No mistery, just provider's default choice. Actually changing from private to public costs nothing. Finally now I observe that WhatIsMyIp address and the address in the router page are the same and probably this can help somebody else to understand the problem: if router's Ip and WhatIsMyIp addresses aren't the same, something similar to my situation is happening. Port forwarding is still necessary. Thanks again for you collaboration, I was abandoning the task, while now things are quite different...
 
Upvote 0
Top