Adding Socket.IO to existing Django/WSGI project

天涯浪子 提交于 2020-01-01 19:31:17

问题


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.


回答1:


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.




回答2:


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()


来源:https://stackoverflow.com/questions/13733137/adding-socket-io-to-existing-django-wsgi-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!