我在寻求帮助。我的django服务器具有通过django-socketio实现的即时消息功能。如果我通过cmd'runserver_socketio'运行服务器,那么没有问题。 但是现在我想通过'runfcgi'运行服务器,但这会让我的socketio无法正常工作。所以我想让socketio服务器处理由fcgi服务器传送的请求。它可以工作吗? 以下是我的代码:django服务器可以向其他服务器发送请求
def push_msg(msg): params = urllib.urlencode({"msg":str(msg)}) '''headers = {"Content-type":"text/html;charset=utf8"} conn = httplib.HTTPConnection("http://127.0.0.1:8000") print conn conn.request("POST", "/push_msg/", data=params, headers=headers) response = conn.getresponse() print response''' h = httplib2.http() print h resp, content = h.request("http://127.0.0.1:8000/push_msg/", method="POST", body=params) url(r'^push_msg/$', 'chat.events.on_message') chat.events.on_message: def on_message(request): msg = request.POST.get('msg') msg = eval(msg) try: print 'handle messages' from_id = int(msg['from_id']) to_id = int(msg['to_id']) user_to = UserProfile.objects.get(id = msg['to_id']) django_socketio.broadcast_channel(msg, user_to.channel) if msg.get('type', '') == 'chat': ct = Chat.objects.send_msg(from_id=from_id,to_id=to_id,content=data['content'],type=1) ct.read = 1 ct.save() except: pass return HttpResponse("success")
我试过很多次,但无法工作,为什么?
这可能会给你一些想法:http://stackoverflow.com/questions/5357635/websockets-fastcgi-or-wsgi-ssl-same-domain-如何 – jozzas