Adding Socket.IO to existing Django/WSGI project

2019-04-16 14:09发布

This guy seems to be trying to do the same thing but the answer to his question isn't clear enough. I'm not all that familiar with setting up socket servers so I'm still a bit lost here. Has anyone accomplished this before? How do you spin up the socket server and keep it running?

I wanted to comment on his post and ask him if he had success but I don't have enough reputation yet.

2条回答
男人必须洒脱
2楼-- · 2019-04-16 14:52

My final solution to this was using the built-in runserver_socketio command for the manage.py script, running on 0.0.0.0:9000. I'm using Ubuntu so I made an upstart config to keep it alive. Seems to be working just fine running alongside my Apache/WSGI server. If anyone has a better solution please speak up.

查看更多
Summer. ? 凉城
3楼-- · 2019-04-16 14:55

A approach I came up with was using the wsgi the apache uses to instance a thread that just calls the runserver_socketio command. That's not, for sure, the best approach. But if someone finds a better solution. Let us know in this post.

def init_socketio():
    os.system('python manage.py runserver_socketio 0.0.0.0:9000')

socketio_thread = Thread(target=init_socketio, args=())
socketio_thread.start()
查看更多
登录 后发表回答