我在 localhost 上运行一个 gae Web 应用程序。我已成功从 goog.channel 生成令牌并将其发送给客户端。客户端能够接受令牌并尝试打开连接的位置。问题是,我正在从我的 servlet 类发送一条消息,而客户端没有发生任何事情。
以下是我的代码:
服务器端:
//for generating token
ChannelService channelService=ChannelServiceFactory.getChannelService();
token = channelService.createChannel(userid);
//for sending message
ChannelService channelService=ChannelServiceFactory.getChannelService();
channelService.sendMessage(new ChannelMessage(userid, message));
//in appengine-web.xml
<inbound-services>
<service>channel_presence</service>
</inbound-services>
Javascript:
function getToken(){
var xmlhttpreq=new XMLHttpRequest();
xmlhttpreq.open('GET',host+'/channelapi_token?q='+user,false);
xmlhttpreq.send();
xmlhttpreq.onreadystatechange=alert(xmlhttpreq.responseText);
token=xmlhttpreq.responseText;
setChannel();
}
function setChannel(){
alert(token);//iam receiving right token here
channel=new goog.appengine.Channel(token);
socket=channel.open();
socket.open=alert('socket opened');//this message alerts
socket.onmessage=alert('socket onmessage');//this message alerts
socket.onerror=alert('socket onerror');//this message alerts
socket.onclose=alert('socket onclose');//this message alerts
}
从 channelservice 发送消息时没有异常。客户端也在反复向我的服务器发出获取请求:
这里发生了什么错误?提前致谢。