package com.server;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.servlet.http.HttpServletRequest;
import org.apache.catalina.websocket.MessageInbound;
import org.apache.catalina.websocket.StreamInbound;
import org.apache.catalina.websocket.WebSocketServlet;
import org.apache.catalina.websocket.WsOutbound;
import com.talk.TalkManager;
public class ServerSocket extends WebSocketServlet {
private static final long serialVersionUID = -4853540828121130946L;
public static Map<String, List<MyMessageInbound>> clients = new ConcurrentHashMap<String, List<MyMessageInbound>>();
private String user_id ;
@Override
protected StreamInbound createWebSocketInbound(String arg0, HttpServletRequest request) {
user_id = request.getParameter( "user_id" );
return new MyMessageInbound();
}
public class MyMessageInbound extends MessageInbound {
public WsOutbound myoutbound;
public String userId = user_id ;
@Override
public void onOpen(WsOutbound outbound) {
try {
System.out.println("Open>>>>>>用户ID为" + userId + "建立连接" );
this.myoutbound = outbound;
if (clients.containsKey(userId)){
List<MyMessageInbound> list = clients.get(userId);
list.add(this);
clients.put(userId, list);
}else{
List<MyMessageInbound> list = new ArrayList<MyMessageInbound>();
list.add(this);
clients.put(userId, list);
}
outbound.writeTextMessage(CharBuffer.wrap("Hello!"));
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onTextMessage(CharBuffer cb) throws IOException {
System.out.println("服务器收到消息 : " + cb);
TalkManager.broadcast(cb.toString());
}
@Override
public void onClose(int status) {
if( status == 1002 || status == 1000)
{
System.out.println("Close>>>>>>用户ID为" + userId + "断开连接" );
List<MyMessageInbound> list = clients.get(userId);
list.remove(this);
}
}
@Override
public void onBinaryMessage(ByteBuffer bb) throws IOException {
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
websocket兼容IE678
共32个文件
class:7个
java:6个
js:4个
5星 · 超过95%的资源 需积分: 15 16 下载量 92 浏览量
2017-02-25
18:09:43
上传
评论
收藏 2.37MB ZIP 举报
温馨提示
利用flash请求模仿websocket协议建立连接。使websocket兼容IE678,部署到tomcat7,运行index.jsp即可。完美运行websocket。
资源推荐
资源详情
资源评论
收起资源包目录
webchat兼容IE678.zip (32个子文件)
webchat
.settings
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.common.project.facet.core.xml 252B
org.eclipse.wst.common.component 457B
org.eclipse.wst.jsdt.ui.superType.container 49B
.jsdtscope 500B
org.eclipse.jdt.core.prefs 598B
src
com
thread
PolicyThread.java 2KB
PolicyServer.java 1KB
server
ServerSocket.java 3KB
servlet
InitServers.java 1KB
talk
TalkManager.java 1KB
utils
SocketUtil.java 2KB
.project 2KB
WebRoot
META-INF
MANIFEST.MF 36B
WEB-INF
web.xml 895B
classes
com
thread
PolicyServer.class 1KB
PolicyThread.class 2KB
server
ServerSocket$MyMessageInbound.class 3KB
ServerSocket.class 1KB
servlet
InitServers.class 1KB
talk
TalkManager.class 2KB
utils
SocketUtil.class 2KB
lib
catalina.jar 1.48MB
tomcat-coyote.jar 776KB
index.jsp 3KB
scripts
jquery.WebSocket.js 3KB
jquery.js 247KB
WebSocketMain.swf 173KB
swfobject.js 10KB
web_socket.js 13KB
.mymetadata 294B
.classpath 708B
.myeclipse
共 32 条
- 1
资源评论
- supertwj2018-11-26还可以的,可用
wlyahoo
- 粉丝: 1
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功