WebSocket - 最大连接数 - 请求不到连接 - 连接数 - 连接
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Testing websockets</title>
</head>
<body>
<div>
<input type="submit" value="Start" onclick="start()" />
</div>
<div id="messages"></div>
<script type="text/javascript">
for (i = 1; i <= 250; i++)
{
document.getElementById('messages').innerHTML += i +'<br />';
var webSocket = new WebSocket('ws://localhost:8080/WebSocket/ws/websocket');
webSocket.onerror = function(event) {
document.getElementById('messages').innerHTML += '<br />' + event.data;
};
webSocket.onopen = function(event) {
document.getElementById('messages').innerHTML += 'Connection established <br />';
};
webSocket.onmessage = function(event) {
document.getElementById('messages').innerHTML += '<br />' + event.data;
};
function start() {
webSocket.send('hello');
return false;
}
}
</script>
</body>
</html>
上面是我的页面代码,js中写了循环,在17行时请求websocket连接
下面是服务器代码,
public class webSocketServletDemo extends WebSocketServlet {
private static final long serialVersionUID = 1L;
int a = 0;
@Override
protected StreamInbound createWebSocketInbound(String arg0,HttpServletRequest request) {
++a;
System.out.println(Runtime.getRuntime().maxMemory()/(1024*1024));
long freeMe=(Runtime.getRuntime().freeMemory())/(1024*1024);
System.out.println(freeMe);
System.out.println("request : " +request);
return new webSocketMessage(a+"");
}
}
public class webSocketMessage extends MessageInbound {
private static Vector<MessageInbound> v = new Vector<MessageInbound>();
private String id = "";
public webSocketMessage(String id){
this.id = id;
}
@Override
protected void onOpen(WsOutbound outbound) {
v.add(this);
System.out.println("当前进入用户ID号 : "+id +" 当前共有用户数 : "+v.size());
}
@Override
protected void onClose(int status) {
super.onClose(status);
System.out.println("onClose - 事件被触发 , status : " + status);
}
@Override
protected void onTextMessage(CharBuffer msg) throws IOException {
System.out.println(this.id+"对"+v.get(1)+"说"+msg);
MessageInbound mib = (MessageInbound)v.get(1);
CharBuffer buffer = CharBuffer.wrap(msg);
mib.getWsOutbound().writeTextMessage(buffer);
}
@Override
protected void onBinaryMessage(ByteBuffer arg0) throws IOException {
}
}目前我只能获取到200个websocket链接,在获取第201个时
执行 - var webSocket = new WebSocket('ws://localhost:8080/WebSocket/ws/websocket');
服务器没有任何输出,好像压根就没执行到servlet.
java Jre内存是足够的,
这种问题 我应该从哪里开始下手解决,
...全文
相关推荐
Springboot多连接池+websocket
Springboot多连接池+websocket,相关详细技术说明可进入我的CSDN看博文哦~~如果有问题可在csdn上留言或者通过QQ694335719联系
简单实用的WebSocket test tools
简单实用的webSocket测试工具,支持ws协议,适合测试Socket最大连接数、最长连接时间测试,不像其他的Socket工具只支持TCP、UDP
vue发送websocket请求和http post请求的实例代码
主要介绍了vue发送websocket请求和http post请求的方法,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值 ,需要的朋友可以参考下
用okhttp实现webSocket长连接
用okhttp实现webSocket长连接,可以接收服务端消息,向服务端发送消息,心跳包,维护长连接
Vue通过WebSocket建立长连接的实现代码
主要介绍了Vue通过WebSocket建立长连接的实现代码,文中给出了问题及解决方案,需要的朋友可以参考下


