我正在寻求帮助。我的 django 服务器有 django-socketio 实现的即时通讯功能。如果我通过 cmd 'runserver_socketio' 运行服务器,则没有问题。但是现在我想通过'runfcgi'运行服务器,但这会使我的socketio无法工作。所以我希望socketio服务器处理fcgi服务器传送的请求。它可以工作吗?以下是我的代码:
def push_msg(味精):
参数 = urllib.urlencode({"msg":str(msg)})
'''headers = {"内容类型":"text/html;charset=utf8"}
conn = httplib.HTTPConnection("http://127.0.0.1:8000")
打印连接
conn.request("POST", "/push_msg/", data=params, headers=headers)
响应 = conn.getresponse()
打印回复'''
h = httplib2.http()
打印 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(请求):
msg = request.POST.get('msg')
味精=评估(味精)
尝试:
打印'处理消息'
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)
如果 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()
除了:
经过
返回 HttpResponse("成功")
我试了很多次,还是不行,为什么?