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
Top