资源简介
基于tomcat的websocket,实现的一对一通讯,支持https协议。
代码片段和文件信息
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License Version 2.0
* (the “License“); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing software
* distributed under the License is distributed on an “AS IS“ BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.zfsoft.terminalManagement.util.websocket;
import java.io.IOException;
import java.nio.CharBuffer;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.atomic.AtomicInteger;
import javax.websocket.OnClose;
import javax.websocket.onerror;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.LogFactory;
import com.zfsoft.terminalManagement.util.websocket.SocketServer.ChatWebSocket;
@ServerEndpoint(value = “/websocket/chat“)
public class ChatAnnotation {
private static final Log log = LogFactory.getLog(ChatAnnotation.class);
// private static final String GUEST_PREFIX = “Guest“;
private static final AtomicInteger connectionIds = new AtomicInteger(0);
private static final Set connections =
new CopyOnWriteArraySet<>();
private String nickname;
private Session session;
public ChatAnnotation() {
nickname = “#“+String.valueOf(connectionIds.getAndIncrement());
}
@OnOpen
public void start(Session session) {
this.session = session;
connections.add(this);
String message = String.format(“* %s %s“ nickname “has joined.“);
System.out.println(“message:“+message);
String msg = “NAME“ + “\t“ + nickname;
try {
this.session.getBasicRemote().sendText(msg);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@OnClose
public void end() {
connections.remove(this);
String message = String.format(“* %s %s“
nickname “has disconnected.“);
broadcast(message);
}
@OnMessage
public void incoming(String message) {
// Never trust the client
String filteredMessage = String.format(“%s: %s“
nickname message.toString());
System.out.println(“filteredMessage:“+filteredMessage);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3700 2017-09-30 16:58 webSocket一对一聊天\chat.jsp
文件 3838 2017-09-30 17:02 webSocket一对一聊天\ChatAnnotation.java
文件 93682 2017-07-28 16:32 webSocket一对一聊天\jquery-1.8.3.min.js
文件 467 2017-09-30 17:04 webSocket一对一聊天\TestController.java
文件 64 2017-09-30 17:06 webSocket一对一聊天\说明.txt
目录 0 2017-09-30 17:05 webSocket一对一聊天
----------- --------- ---------- ----- ----
101751 6
相关资源
- 易语言websocket服务器源码
- websocket规范 RFC6455 中文版
- websocket-rtsp-proxy-test.zip
- tomcat7.0.42 下部署websocket需要替换的包
- 物联网,WEBSOCKET丰富案例
- websocket简单web项目,直接部署可使用
- 高德地图+websocket
- libwebsockets-v1.6-stable.tar.gz
- weblogic websocket
- websocket
- 基于spring websocket实现广播及点对点推
- tomcat实现websocket聊天室
- 叫号语音平台源码
- springboot+websocket实现聊天室
- 用okhttp实现webSocket长连接
- node.js+socket.io+websocket使用demo
- websocket 1V1聊天室
- 简单的在线聊天室实现群聊和单聊,
- e语言-58自动回复招聘方源码 websocke
- libwebsockets-master
- Springboot多连接池+websocket
- SuperWebSocket使用
- libwebsockets-master.rar
- websocket实现单聊和群聊
- websocket服务端与客户端通信
- WEB在线聊天系统源码
- websocket向指定用户发信息
- Spring Boot整合websocket实现群聊,点对点
- 基于vs2010做的tcp通信调试工具源码
- Web网盘,WebSocket通讯
评论
共有 条评论