×

创建websocket失败 ox

创建websocket失败(firefox使用websocket无法建立到ws://服务器的连接错误,这是什么原因呢)

admin admin 发表于2024-01-26 01:15:46 浏览32 评论0

抢沙发发表评论

大家好,创建websocket失败相信很多的网友都不是很明白,包括firefox使用websocket无法建立到ws://服务器的连接错误,这是什么原因呢也是一样,不过没有关系,接下来就来为大家分享关于创建websocket失败和firefox使用websocket无法建立到ws://服务器的连接错误,这是什么原因呢的一些知识点,大家可以关注收藏,免得下次来找不到哦,下面我们开始吧!

本文目录

firefox使用websocket无法建立到ws://服务器的连接错误,这是什么原因呢

1.打开firefox,输入 about:config,进入配置页

2.搜索websocket配置项

3.配置如下图所示

4.修改配置后,需要重新启动Firefox

页面访问java websocket服务时,出现异常,Firefox下的异常是:Firefox 无法建立到 ws://... 服务器的连接;

IE下的异常是:WebSocket Error: Incorrect HTTP response. Status code 404, Not Found

环境是:apache-tomcat-7.0.62、jdk1.7.0_67、@ServerEndpoint("/websocket")这种声明式写法

我的排查步骤:

1、tomcat的JAVA_HOME指向jdk7

2、Firefox参数调整,据说默认是关闭websocket的,但是我的版本是38.0.6,没有关闭

***隐藏网址******隐藏网址***

4、最后发现,是由于我引入了一个javax.websocket-api.jar放到了WEB-INF/lib/下面,可能跟tomcat7的websocket-api.jar有冲突。

去掉javax.websocket-api.jar后异常消失

 view plain copy

《!DOCTYPE html》  

《html》  

《head》  

《meta charset="UTF-8"》  

《title》Testing websocket《/title》  

《/head》  

《body》  

《div》  

《input type="submit" value="Start" onclick="start()" /》  

《input type="button" value="Stop" onclick="stop()" /》  

《/div》  

《div id="messages"》《/div》  

《script type="text/javascript"》  

console.log(window.WebSocket);  

var webSocket = new WebSocket(’ws://127.0.0.1:8088/WebModule/websocket’);  

webSocket.onerror = function(event) {  

onError(event)  

};  

webSocket.onopen = function(event) {  

onOpen(event)  

};  

/* webSocket.onclose = function(event){  

alert("要离开了?");  

}; */  

webSocket.onmessage = function(event) {  

onMessage(event)  

};  

function onMessage(event) {  

document.getElementById(’messages’).innerHTML += ’《br /》’  

+ event.data;  

}  

function onOpen(event) {  

document.getElementById(’messages’).innerHTML = ’Connection established’;  

}  

function onError(event) {  

alert(event.data);  

}  

function start() {  

webSocket.send(’hello’);  

return false;  

}  

function stop() {  

webSocket.send(’bye bye!’);  

webSocket.close();  

}  

《/script》  

《/body》  

《/html》  

 view plain copy

import java.io.IOException;  

import javax.websocket.OnClose;  

import javax.websocket.OnMessage;  

import javax.websocket.OnOpen;  

import javax.websocket.Session;  

import javax.websocket.server.ServerEndpoint;  

@ServerEndpoint("/websocket")  

public class WebSocketTest {  

@OnMessage  

public void onMessage(String message, Session session) throws IOException, InterruptedException{  

// Print the client message for testing purposes  

System.out.println("Received: " + message);  

// Send the first message to the client  

session.getBasicRemote().sendText("This is the first server message");  

// Send 3 messages to the client every 5 seconds  

int sentMessages = 0;  

while(sentMessages 《 3){  

Thread.sleep(5000);  

session.getBasicRemote().sendText("This is an intermediate server message. Count: " + sentMessages);  

sentMessages++;  

}  

// Send a final message to the client  

session.getBasicRemote().sendText("This is the last server message");  

}  

@OnOpen   

public void onOpen(){  

System.out.println("Client connected");  

}  

@OnClose  

public void onClose(){  

System.out.println("Connection closed");  

}  

}  

如何创建使用SuperWebSocket一个WebSocket的服务器

如何创建使用SuperWebSocket一个WebSocket的服务器这里WebSocketServer对象通过Setup方式对要侦听的IP及端口进行了设置。然后使用Start方法启动侦听。Setup方法有4种重载,但是我们通常用到的只有设置IP和端口,IP为string类型,如果传入的字符串无法被转换为支持的IP格式,Setup方法会返回false表示设置失败。WebSocketServer还提供了4个事件用以管理与客户端的连接、断开、和接受消息动作。新版本的WebSocket支持传送的数据格式有 “文本” 和 “二进制”两种,NewMessageReceived事件用于处理文本类型的消息,NewDataReceived事件用于处理二进制类型的消息。

webSocket注入service失败解决方法

websocket里无法注入其它@Compenent 和@Service等单例组件 websocket 不是单例,是动态生成的,因此无法注入单例组件

C 实现的 WebSocket 服务器握手失败

WebSocket是HTML5开始提供的一种浏览器与服务器间进行全双工通讯的网络技术。在WebSocketAPI中,浏览器和服务器只需要做一个握手的动作,然后,浏览器和服务器之间就形成了一条快速通道。两者之间就直接可以数据互相传送。

javaweb项目使用了websocket,项目发布到公司服务器后websocket报404错误!请问,可能是什么原因引起的~

我碰到比较常见的原因:

  1. 你的项目在服务器上面运行出了问题,没有正常运行起来,这个一般可以通过容器的控制台检查

  2. 你房补到服务器的项目路径有改变,所以你的请求地址错了

系统网页提示Wedstorkte未建立连接

你想问系统网页提示webSocket未建立连接的问题吧,有以下几个原因:1、客户端链接WebSocket服务器时连接失败:部署项目的时候如果项目的wen-inf的lib下也有websocket-api-jar会冲突,导致连接不上。2、本地运行正常,连接到服务器上时出错:在调试远程服务器的Websocket程序时,要关闭本地的Tomcat服务器。3、客户端链接WebSocket服务器成功后,测试消息推送获取session失败:地址输入不正确,检查地址。

OK,关于创建websocket失败和firefox使用websocket无法建立到ws://服务器的连接错误,这是什么原因呢的内容到此结束了,希望对大家有所帮助。