1.导入websoket-api.jar包
2.相当于controller的继承TextWebSocketHandler的处理类
package boss.net.controller.cp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.socket.handler.TextWebSocketHandler;
import org.springframework.web.socket.server.standard.SpringConfigurator;
import javax.websocket.*;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.concurrent.CopyOnWriteArraySet;
@ServerEndpoint(value = "/webSocket/log",configurator = SpringConfigurator.class) //相当于@requstMapping
public class LogController extends TextWebSocketHandler {
//静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。
private static int onlineCount = 0;
public void LogController(){
}
//concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。