未能分析从服务器收到的消息,WebSocket Javascript客户端未收到来自服务器的消息...

我已经在本地GlassFish 4.1服务器上部署了Java Web应用程序,该服务器实现了与Web客户端互操作的WebSockets。我能够通过套接字成功执行客户端到服务器的通信,但由于某种原因,服务器到客户端的通信不起作用。WebSocket Javascript客户端未收到来自服务器的消息

将消息发送到客户端的Java代码:

try

{

String msg = ServerClientInteropManager.toResponseJSON(response);

parentSession.getBasicRemote().sendText(msg);

FLAIRLogger.get().info("Sent response to client. Message: " + msg);

}

catch (IOException ex) {

FLAIRLogger.get().error("Couldn't send message to session " + parentSession.getid() + ". Exception - " + ex.getMessage());

}

的JavaScript代码:

pipeline_internal_onMessage = function(event)

{

var msg = JSON.parse(event.data);

console.log("Received message from server. Data: " + event.data);

};

function pipeline_init()

{

if (PIPELINE !== null || PIPELINE_CONNECTED === true)

{

console.log("Pipline already initialized");

return false;

}

else

{

var pipelineURI = "ws://" + document.location.host + document.location.pathname + "webranker";

console.log("Attempting to establish connection with WebSocket @ " + pipelineURI);

if ('WebSocket' in window)

PIPELINE = new WebSocket(pipelineURI);

else if ('MozWebSocket' in window)

PIPELINE = new MozWebSocket(pipelineURI);

else

{

console.log("FATAL: No WebSockets support");

alert("This browser does not support WebSockets. Please upgrade to a newer version or switch to a browser that supports WebSockets.");

return false;

}

// the other event listeners get added here

PIPELINE.onMessage = pipeline_internal_onMessage;

PIPELINE_CONNECTED = true;

window.onbeforeunload = function() {

pipeline_deinit();

};

console.log("Pipeline initialized");

return true;

}

}

在onMessage功能从来没有发射,即使在服务器成功调用sendText()方法。使用AsyncRemote产生相同的结果。两端的onError侦听器也不会报告任何内容。这是我第一次使用套接字,所以我可能会错过一些基本的东西。

2016-03-05

shadeMe

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值