piotrwilk
Posts: 4
Joined: Sat May 09, 2015 3:46 pm

www and Tornado websocket server

Sat May 09, 2015 3:52 pm

I've got www server(apache2) and Tornado websocket server on my Rpi. The problem is can't see data refreshing via websocket outside my local network. What should I set to have possibility watch data on eg. my phone?
I set forwarding on my router: port80->Rpi IP address (192.168.1.103). I attrached the most important (I guess) parts of code.

Part of "mypage.php" code:

Code: Select all

<script>
   $(document).ready(function () 
   {
	var ws = new WebSocket("ws://192.168.1.103:8888/ws");
	ws.onopen = function(evt) 
	{
	     var conn_status = document.getElementById('conn_text');
	     conn_status.innerHTML = "Connection status: Connected!"
    	};
	...
	...	
	...
   }
Part of "server.py" code:

Code: Select all

	...
	...	
	http_server = tornado.httpserver.HTTPServer(application)
	http_server.listen(8888)
        main_loop = tornado.ioloop.IOLoop.instance()
        sched_temp = tornado.ioloop.PeriodicCallback(read_devices, interval_msec, io_loop = main_loop)
        sched_temp.start()
        main_loop.start()
Best regards,
PW

ghellquist
Posts: 68
Joined: Thu Aug 02, 2012 8:47 am
Location: Stockholm Sweden

Re: www and Tornado websocket server

Sat May 23, 2015 1:31 pm

I set forwarding on my router: port80->Rpi IP address (192.168.1.103).
The router has a totally different adress on the internet and translates that adress using NAT.
You need to point your phone to the current router adress (connect to the router and check which adress it has).
There are two problems:
1) the router internet IP-adress will change at any time, and you have no control over that.
2) the network supplier might stop incoming requests.

You need to check with the network supplier if they allow incoming traffic to your router, and if they might be able to supply you with a fixed IP adress (it might cost you a bit extra)

//Gunnar

User avatar
DougieLawson
Posts: 36540
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: www and Tornado websocket server

Sat May 23, 2015 1:46 pm

How does your RPi connect to the public Internet?

Find your public IP address with this command: curl -s http://httpbin.org/ip | awk '{print $2}' then compare that to the address that your SoHo router/switch/access point thinks is your public IP address.

You'll then want to look at a service like No-IP to give your public IP address a domain name and have No-IP automatically update if your public IP address changes.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

piotrwilk
Posts: 4
Joined: Sat May 09, 2015 3:46 pm

Re: www and Tornado websocket server

Sat May 23, 2015 10:58 pm

I'm using no-ip.org and every content of my website is visible on internet except data from tornado server. The data as I mentioned are visible only in local network. I wonder is it problem with configuration of apache? Maybe something else?

PW

User avatar
topguy
Posts: 5936
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: www and Tornado websocket server

Sat May 23, 2015 11:06 pm

You are using port no. 8888 in your code but you only mention port forwarding of port 80. You either missing a port forward or miswrote something in your post.
You are also using your LAN address, which wont work either from an internet client.

piotrwilk
Posts: 4
Joined: Sat May 09, 2015 3:46 pm

Re: www and Tornado websocket server

Sat May 23, 2015 11:30 pm

I tried:

Code: Select all

var ws = new WebSocket("ws://localhost:8888/ws");
but it doesn't work even on local network.
Forwarding port no. 8888 -> 192.168.1.103:8888 also doesn't help.

PW

piotrwilk
Posts: 4
Joined: Sat May 09, 2015 3:46 pm

Re: www and Tornado websocket server

Sat May 23, 2015 11:51 pm

OK, it works. The solution is forwarding port no.8888 and to use correct web address :)

e.g.:

Code: Select all

var ws = new WebSocket("ws://myhomepage.ddns.net:8888/ws");
It should be obviosu for me :(. Thanks everyone for clues.

Return to “Networking and servers”