Running the server and client on mac with localhost everything works fine.
Running the python program (server) on the raspberry pi and try to access it using its url doesn't work.
Python Server:
class Strompreisgenerator:
def __init__(self):
self.ws = websockets.serve(self.echo, 'localhost', 5001)
asyncio.get_event_loop().run_until_complete(self.ws)
asyncio.get_event_loop().run_forever()
async def echo(self, websocket, path):
async for message in websocket:
print(message)
Javascript Client:
var ws = new WebSocket("ws://www.tobiasschmocker.ch:5001");
While trying to instantiate the WebSocket the error "WebSocket network error: The operation couldn’t be completed. Connection refused" occurs in safari.
The Port 5001 is open on RPi. I also tried local IP. I forwarded the Port on my router but still nothing. If i trie other urls i get another error, so i suppose the url is correct but i have no rights somehow.
On my RPi i have ssh enabled, also php, apache, mysql and all the pip packages for my python server.
If you know, where the problem lies, i'd be happy to know. Thank you very much!
nc -v www.tobiasschmocker.ch 5001nc -v www.tobiasschmocker.ch 5001i get:nc: connect to www.tobiasschmocker.ch port 5001 (tcp) failed: Connection refusedpython3 path/Strompreisgenerator.py. There is also a MQTT-Clients publishing in the program. The MQTT-Broker runs on port 1883 on www.tobiasschmocker.ch and for now i publish on the topic "Sarah" using a cronjob. I hope this is not interfering with the websocket. MQTT works fine, but the websocket doesnt. I have this problem only if i run the program on the RPi - on my mac it works fine. I'll keep the program running if you want to try out the Websocket or MQTT.