Question

How do I use my droplet as a server using the python websockets module?

I’m a complete beginner to network programming. I’m writing a program to allow me to play board games with my friends throughout isolation (I know, I know, there are already similar programs available online, but I want to make my own to make myself a better programmer). I’m trying to use the websockets library on python to allow me and my friends to connect to the droplet I’ve set up. When my client tried to connect to the server I get the following error:

RuntimeError                              Traceback (most recent call last)
~\Desktop\test_program\client2.py in <module>
     23 
     24 
---> 25 asyncio.get_event_loop().run_until_complete(communicate())

~\AppData\Local\Continuum\anaconda3\lib\asyncio\base_events.py in run_until_complete(self, future)
    558         future.add_done_callback(_run_until_complete_cb)
    559         try:
--> 560             self.run_forever()
    561         except:
    562             if new_task and future.done() and not future.cancelled():

~\AppData\Local\Continuum\anaconda3\lib\asyncio\base_events.py in run_forever(self)
    513         self._check_closed()
    514         if self.is_running():
--> 515             raise RuntimeError('This event loop is already running')
    516         if events._get_running_loop() is not None:
    517             raise RuntimeError(

RuntimeError: This event loop is already running

Does anyone know what I might be doing incorrectly? Could it be an issue with the firewall on my computer or on my droplet?

Thanks, Robert


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there @robertwdg,

It does not look like a firewall problem. I can see that there was a similar problem reported here and what fixed the problem for the user was installing nest_asyncio:

  1. pip install nest_asyncio

And adding the following lines:

import nest_asyncio
nest_asyncio.apply()

Let me know how it goes! Regards, Bobby