Java后端使用socketio,实现小程序答题pk功能

在使用socket.io跟前端通信过程中,出现了一系列问题,现做下记录。

一、功能需求

在小程序端,用户可相互邀请,进入房间后进行答题PK。实现方法是,用户点击邀请好友,建立连接,查询当前是否有房间,有房间发送消息给两人,匹配成功,开始pk。没有房间新建房间返回,等待20秒,等待别人匹配。

代码如下,先看配置,在application.yml配置文件中增加如下配置

Java后端使用socketio,实现小程序答题pk功能

配置类

package com.cwn.wethink.remy.handler;
 
import com.corundumstudio.socketio.SocketConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
 
import com.corundumstudio.socketio.SocketIOServer;
 
/**
 * @description:
 * @author: m1575
 * @create: 2020-11-11
 **/
@Configuration
class SocketIOConfig {
 
@Value("${socketio.host}")
private String host;
 
@Value("${socketio.port}")
private Integer port;
 
@Value("${socketio.bossCount}")
private int bossCount;
 
@Value("${socketio.workCount}")
private int workCount;
 
@Value("${socketio.allowCustomRequests}")
private boolean allowCustomRequests;
 
@Value("${socketio.upgradeTimeout}")
private int upgradeTimeout;
 
@Value("${socketio.pingTimeout}")
private int pingTimeout;
 
@Value("${socketio.pingInterval}")
private int pingInterval;
 
/**
 * 以下配置在上面的application.properties中已经注明
 * @return
 */
@Bean
public SocketIOServer socketIOServer() {
SocketConfig socketConfig = new SocketConfig();
socketConfig.setTcpNoDelay(true);
socketConfig.setSoLinger(0);
com.corundumstudio.socketio.Configuration config = new com.corundumstudio.socketio.Configuration();
config.setSocketConfig(socketConfig);
config.setHostname(host);
config.setPort(port);
config.setBossThreads(bossCount);
config.setWorkerThreads(workCount);
config.setAllowCustomRequests(allowCustomRequests);
config.setUpgradeTimeout(upgradeTimeout);
config.setPingTimeout(pingTimeout);
config.setPingInterval(pingInterval);
return new SocketIOServer(config);
}
}

后台实现

package com.cwn.wethink.remy.handler;
 
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import com.alibaba.fastjson.JSONObject;
import com.corundumstudio.socketio.*;
import com.cwn.wethink.pojo.entity.Question;
import com.cwn.wethink.remy.entity.PkAgainGame;
import com.cwn.wethink.remy.entity.PkAnswerTime;
import com.cwn.wethink.remy.entity.PkGroup;
import com.cwn.wethink.remy.entity.WxUserInfo;
import com.cwn.wethink.remy.mapper.PkMapper;
import com.cwn.wethink.remy.mapper.WxUserInfoMapper;
import com.cwn.wethink.remy.service.RemyCourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
@Service
@Slf4j
public class MessageEventHandler {
 
// 用来存已连接的客户端
private static Map<Long, SocketIOClient> clientMap = new ConcurrentHashMap<>();
 
@Autowired
private SocketIOServer socketIOServer;
 
@Autowired
private PkMapper pkMapper;
 
@Autowired
private WxUserInfoMapper wxUserInfoMapper;
 
@Autowired
private RemyCourseService remyCourseService;
 
/**
 * Spring IoC容器创建之后,在加载SocketIOServiceImpl Bean之后启动
 * @throws Exception
 */
@PostConstruct
private void autoStartup() throws Exception {
start();
}
 
/**
 * Spring IoC容器在销毁SocketIOServiceImpl Bean之前关闭,避免重启项目服务端口占用问题
 * @throws Exception
 */
@PreDestroy
private void autoStop() throws Exception {
stop();
}
 
public void start() {
// 监听客户端连接,同级挑战比拼
socketIOServer.addConnectListener(client -> {
Long uid = Long.valueOf(getParamsByClient(client));
log.info("connect come in,uid:{}",uid);
//0为同级挑战,1为邀请好友pk
int type = 0;
//房间号
int pkId = 0;
//从请求的连接中拿出参数
Map<String, List<String>> params = client.getHandshakeData().getUrlParams();
List<String> list = params.get("type");
if (list != null && list.size() > 0) {
type = Integer.valueOf(list.get(0));
}
List<String> list1 = params.get("pkId");
if (list1 != null && list1.size() > 0) {
pkId = Integer.valueOf(list1.get(0));
}
if (uid != null) {
if (clientMap.containsKey(uid)) {
log.info(uid + "is reconnect");
clientMap.remove(uid);
clientMap.put(uid , client);
}else{
clientMap.put(uid, client);
log.info("clientMap:"+clientMap);
joinSendMessage(uid , client , type , pkId);
}
}
});
 
// 监听客户端断开连接
socketIOServer.addDisconnectListener(client -> {
Long uid = Long.valueOf(getParamsByClient(client));
log.info("disconnect come in,uid:{}",uid);
if (uid != null) {
log.info("uid is not null come in,uid:{}",uid);
clientMap.remove(uid);
client.disconnect();
//退出通知对手
Long usrEntId = 0l;
PkGroup pkGroup = pkMapper.getPkGroupUserNewRoom(uid);
if(pkGroup != null){
log.info("pkGroup is not null come in,uid:{}",uid);
if(uid == pkGroup.getInviteUsrEntId()){
usrEntId = pkGroup.getAcceptUsrEntId();
}else if(uid == pkGroup.getAcceptUsrEntId()){
usrEntId = pkGroup.getInviteUsrEntId();
}
}
if(usrEntId != null && usrEntId != 0l){
log.info("usrEntId is not null come in,uid:{}",uid);
log.info("socketIOClient usrEntId:" + usrEntId);
JSONObject jsonObject = new JSONObject();
SocketIOClient socketIOClient = clientMap.get(usrEntId);
if(socketIOClient != null){
jsonObject.put("disconnect" , 1);
socketIOClient.sendEvent("ClientReceive" , jsonObject);
}
}
if(clientMap.get(usrEntId) == null || usrEntId == null){
if(pkGroup != null){
PkGroup updatePkGroup = pkMapper.getPkGroupById(pkGroup.getId());
updatePkGroup.setState(2);
pkMapper.updatePkGroup(updatePkGroup);
log.info("disconnect opponent is disconnect,uid:{}",uid);
}
}
}
log.info("disconnect is success,uid:{}",uid);
});
 
// 处理自定义的事件,与连接监听类似
// 此示例中测试的json收发 所以接收参数为JSONObject 如果是字符类型可以用String.class或者Object.class
socketIOServer.addEventListener("ServerReceive",JSONObject.class, (client, data, ackSender) -> {
JSONObject jsonObject = data;
if(data != null){
String uid = jsonObject.getString("usrEntId");
String action = jsonObject.getString("action");
if("getAI".equals(action)){
log.info("getAI come in,uid:{}",uid);
//和人机pk返回
botSendMessage(uid , client);
}else if("challenge".equals(action)){
log.info("challenge come in,uid:{}",uid);
//pk过程中每做一道题返回消息给两个人
int pkId = 0;
if(!"".equals(jsonObject.getString("pkId"))){
pkId = Integer.valueOf(jsonObject.getString("pkId"));
}
if(pkId == 0){
log.info("challenge pkId is 0");
return;
}
long usrEntId = -1;
if(!"".equals(jsonObject.getString("usrEntId"))){
usrEntId = Long.valueOf(jsonObject.getString("usrEntId"));
}
if(usrEntId == -1){
log.info("challenge usrEntId is -1");
return;
}
int answer = 0;
if(!"".equals(jsonObject.getString("answer"))){
answer = Integer.valueOf(jsonObject.getString("answer"));
}
int time = 0;
if(!"".equals(jsonObject.getString("time"))){
time = Integer.valueOf(jsonObject.getString("time"));
}
int queResId = 0;
if(!"".equals(jsonObject.getString("queResId"))){
queResId = Integer.valueOf(jsonObject.getString("queResId"));
}
int orderNum = 0;
if(!"".equals(jsonObject.getString("orderNum"))){
orderNum = Integer.valueOf(jsonObject.getString("orderNum"));
}
int option = 0;
if(!"".equals(jsonObject.getString("option"))){
option = Integer.valueOf(jsonObject.getString("option"));
}
PkAnswerTime pkAnswerNow = new PkAnswerTime();
pkAnswerNow.setPkGroupId(pkId);
pkAnswerNow.setUsrEntId(usrEntId);
pkAnswerNow.setAnswer(answer);
pkAnswerNow.setTime(time);
pkAnswerNow.setQueResId(queResId);
pkAnswerNow.setOrderNum(orderNum);
pkAnswerNow.setOption(option);
pkMapper.savePkAnswerTime(pkAnswerNow);
PkGroup pkGroup = pkMapper.getPkGroupById(pkId);
if(usrEntId == pkGroup.getInviteUsrEntId()){
long acceptUsrEntId = pkGroup.getAcceptUsrEntId();
judgeWinner(acceptUsrEntId , pkAnswerNow ,client);
}else if(usrEntId == pkGroup.getAcceptUsrEntId()){
long inviteUsrEntId = pkGroup.getInviteUsrEntId();
judgeWinner(inviteUsrEntId , pkAnswerNow ,client);
}
}else if("again".equals(action)){
log.info("again come in");
//再来一局
int pkId = Integer.valueOf(jsonObject.getString("pkId"));
log.info("pkId:"+pkId+"uid:"+uid);
againSendMessage(uid , pkId, client);
}else if("skill".equals(action)){
//使用技能
int pkId = Integer.valueOf(jsonObject.getString("pkId"));
//技能id
int infoId = Integer.valueOf(jsonObject.getString("info"));
skillSendMessage(uid , pkId , infoId);
}
}
});
 
socketIOServer.start();
log.info("socket.io初始化服务完成");
}
 
public void stop() {
if (socketIOServer != null) {
socketIOServer.stop();
socketIOServer = null;
}
log.info("socket.io服务已关闭");
}
 
/**
 * 此方法为获取client连接中的参数,可根据需求更改
 * @param client
 * @return
 */
private String getParamsByClient(SocketIOClient client) {
// 从请求的连接中拿出参数(这里的usrEntId必须是唯一标识)
Map<String, List<String>> params = client.getHandshakeData().getUrlParams();
List<String> list = params.get("usrEntId");
if (list != null && list.size() > 0) {
return list.get(0);
}
return null;
}
 
private synchronized void joinSendMessage(long usrEntId , SocketIOClient client , int type , int pkId){
// 给客户端发送一条信息 发送ConnectReceive事件 需要客户端绑定此事件即可接收到消息
JSONObject jsonObject = new JSONObject();
Date date = new Date(new Date().getTime() - 20000);
PkGroup pkGroup = pkMapper.getPkGroupByState(usrEntId , type , date);
if(type != 0 && pkId != 0){
pkGroup = pkMapper.getPkGroupById(pkId);
}
if(type != 0 && pkId == 0){
pkGroup = null;
}
if(pkGroup != null){
pkGroup.setAcceptUsrEntId(usrEntId);
pkGroup.setState(1);
pkMapper.updatePkGroup(pkGroup);
long inviteUsrEntId = pkGroup.getInviteUsrEntId();
WxUserInfo invite = wxUserInfoMapper.queryWxUserInfoByUsrEntId(inviteUsrEntId);
List<Question> questions = remyCourseService.listGetRandomTopic(0);
jsonObject.put("state" , 1);
jsonObject.put("wxUserInfo" , invite);
jsonObject.put("questions" , questions);
jsonObject.put("pkId" , pkGroup.getId());
client.sendEvent("ConnectReceive",jsonObject);
SocketIOClient socketIOClient = clientMap.get(inviteUsrEntId);
WxUserInfo accept = wxUserInfoMapper.queryWxUserInfoByUsrEntId(usrEntId);
JSONObject acceptJson = new JSONObject();
acceptJson.put("state" , 1);
acceptJson.put("questions" , questions);
acceptJson.put("pkId" , pkGroup.getId());
acceptJson.put("wxUserInfo" , accept);
socketIOClient.sendEvent("ConnectReceive" , acceptJson);
}else{
PkGroup savePkGroup = new PkGroup();
savePkGroup.setInviteUsrEntId(usrEntId);
savePkGroup.setState(0);
savePkGroup.setCreateTime(new Date());
savePkGroup.setType(type);
pkMapper.savePkGroup(savePkGroup);
jsonObject.put("state" , 0);
jsonObject.put("pkId" , savePkGroup.getId());
client.sendEvent("ConnectReceive",jsonObject);
}
}
 
private synchronized void botSendMessage(String uid , SocketIOClient client){
JSONObject jsonObject = new JSONObject();
PkGroup pkGroup = pkMapper.getPkGroupByUsrEntIdToAI(Long.valueOf(uid));
if(pkGroup != null){
log.info("getAI pkGroup is not null come in,uid:{}",uid);
pkGroup.setAcceptUsrEntId(0l);
pkGroup.setState(1);
pkMapper.updatePkGroup(pkGroup);
List<Question> questions = remyCourseService.listGetRandomTopic(0);
jsonObject.put("state" , 1);
jsonObject.put("questions" , questions);
jsonObject.put("pkId" , pkGroup.getId());
client.sendEvent("AIReceive",jsonObject);
}
}
 
private synchronized void judgeWinner(long anotherEntId , PkAnswerTime pkAnswerNow, SocketIOClient client){
log.info("judgeWinner come in,anotherEntId:{}",anotherEntId);
int pkId = pkAnswerNow.getPkGroupId();
int orderNum = pkAnswerNow.getOrderNum();
int answer = pkAnswerNow.getAnswer();
int time = pkAnswerNow.getTime();
long usrEntId = pkAnswerNow.getUsrEntId();
int option = pkAnswerNow.getOption();
JSONObject json = new JSONObject();
PkAnswerTime pkAnswerTime = pkMapper.getPkAnswerTimeByParam(anotherEntId , pkId , orderNum);
if(pkAnswerTime != null){
log.info("judgeWinner pkAnswerTime is not null come in,pkAnswerTime:{}",pkAnswerTime);
PkGroup pkGroup = pkMapper.getPkGroupById(pkId);
if(orderNum == 5){
pkGroup.setState(2);
pkMapper.updatePkGroup(pkGroup);
}
long winUsrEntId = -1;
if(pkAnswerTime.getAnswer() == 1 && answer == 1){
if(time > pkAnswerTime.getTime()){
winUsrEntId = anotherEntId;
}else if(time < pkAnswerTime.getTime()){
winUsrEntId = usrEntId;
}else{
winUsrEntId = -1;
}
}else if(pkAnswerTime.getAnswer() == 1){
winUsrEntId = anotherEntId;
}else if(answer == 1){
winUsrEntId = usrEntId;
}else{
winUsrEntId = -1;
}
json.put("winUsrEntId" , winUsrEntId);
json.put("pkId" , pkId);
json.put("usrEntId" , anotherEntId);
json.put("answer" , pkAnswerTime.getAnswer());
json.put("time" , pkAnswerTime.getTime());
json.put("option" , pkAnswerTime.getOption());
client.sendEvent("challengeReceive",json);
if(anotherEntId != 0){
SocketIOClient socketIOClient = clientMap.get(anotherEntId);
JSONObject acceptJson = new JSONObject();
acceptJson.put("pkId" , pkId);
acceptJson.put("usrEntId" , usrEntId);
acceptJson.put("answer", answer);
acceptJson.put("time", time);
acceptJson.put("option",option);
acceptJson.put("winUsrEntId",winUsrEntId);
socketIOClient.sendEvent("challengeReceive" , acceptJson);
}
if(pkGroup.getInviteUsrEntId() == winUsrEntId){
if(pkGroup.getInviteNum() != null){
pkGroup.setInviteNum(pkGroup.getInviteNum() + 1);
}else{
pkGroup.setInviteNum(1);
}
}else if(pkGroup.getAcceptUsrEntId() == winUsrEntId){
if(pkGroup.getAcceptNum() != null){
pkGroup.setAcceptNum(pkGroup.getAcceptNum() + 1);
}else{
pkGroup.setAcceptNum(1);
}
}
pkMapper.updatePkNum(pkGroup);
}
}
 
private synchronized void againSendMessage(String uid , int pkId , SocketIOClient client){
JSONObject json = new JSONObject();
long usrEntId = Long.valueOf(uid);
PkGroup pkGroup = pkMapper.getPkGroupById(pkId);
log.info("againSendMessage pkGroup:"+pkGroup);
long opponentId = -1;
if(pkGroup.getAcceptUsrEntId() != null){
if(usrEntId == pkGroup.getAcceptUsrEntId()){
opponentId = pkGroup.getInviteUsrEntId();
}else{
opponentId = pkGroup.getAcceptUsrEntId();
}
}
PkAgainGame pkAgainGame = pkMapper.getPkAgainGame(opponentId , pkId);
log.info("againSendMessage pkAgainGame:"+pkAgainGame);
if(pkAgainGame == null){
PkAgainGame againGame = new PkAgainGame();
againGame.setCreateTime(new Date());
againGame.setUsrEntId(usrEntId);
againGame.setPkGroupId(pkId);
pkMapper.savePkAgainGame(againGame);
json.put("usrEntId" , usrEntId);
json.put("state" , 0);
SocketIOClient socketIOClient = clientMap.get(opponentId);
log.info("againSendMessage socketIOClient:"+socketIOClient);
socketIOClient.sendEvent("AgainReceive" , json);
}else{
pkAgainGame.setOpponentUsrEntId(usrEntId);
pkMapper.updatePkAgainGame(pkAgainGame);
//创建房间
PkGroup savePkGroup = new PkGroup();
savePkGroup.setAcceptUsrEntId(usrEntId);
savePkGroup.setInviteUsrEntId(opponentId);
savePkGroup.setState(1);
savePkGroup.setCreateTime(new Date());
savePkGroup.setType(pkGroup.getType());
pkMapper.savePkGroup(savePkGroup);
List<Question> questions = remyCourseService.listGetRandomTopic(0);
log.info("againSendMessage questions:"+questions);
json.put("state" , 1);
json.put("questions" , questions);
json.put("pkId" , savePkGroup.getId());
if(opponentId == 0){
json.put("wxUserInfo" , "");
}else{
WxUserInfo invite = wxUserInfoMapper.queryWxUserInfoByUsrEntId(opponentId);
json.put("wxUserInfo" , invite);
}
client.sendEvent("AgainReceive",json);
if(opponentId != 0 && opponentId != -1){
SocketIOClient socketIOClient = clientMap.get(opponentId);
JSONObject acceptJson = new JSONObject();
acceptJson.put("state" , 1);
acceptJson.put("questions" , questions);
acceptJson.put("pkId" , savePkGroup.getId());
WxUserInfo accept = wxUserInfoMapper.queryWxUserInfoByUsrEntId(usrEntId);
acceptJson.put("wxUserInfo" , accept);
log.info("againSendMessage socketIOClient:"+socketIOClient);
socketIOClient.sendEvent("AgainReceive" , acceptJson);
}
}
}
 
private void skillSendMessage(String uid , int pkId , int infoId){
JSONObject json = new JSONObject();
long usrEntId = Long.valueOf(uid);
PkGroup pkGroup = pkMapper.getPkGroupById(pkId);
log.info("skillSendMessage pkGroup:"+pkGroup);
long opponentId = -1;
if(usrEntId == pkGroup.getAcceptUsrEntId()){
opponentId = pkGroup.getInviteUsrEntId();
}else{
opponentId = pkGroup.getAcceptUsrEntId();
}
json.put("usrEntId" , usrEntId);
json.put("skill" , 1);
json.put("info" , infoId);
SocketIOClient socketIOClient = clientMap.get(opponentId);
log.info("skillSendMessage socketIOClient:"+socketIOClient);
socketIOClient.sendEvent("SkillReceive" , json);
}
}

 二、遇到的一些问题

1、最初在发送消息给两人时,有个人能收到消息,有个人收不到

刚开始clientMap是这样声明的:

private static Map<String, SocketIOClient> clientMap = new ConcurrentHashMap<>();

但我在查询用户SocketIOClient时使用的是long类型,所以一直没查到用户的SocketIOClient,也就发送消息发不过去。

后面改为
private static Map<Long, SocketIOClient> clientMap = new ConcurrentHashMap<>();

这样声明还是获取不到,继而检查代码,开始返回给两个人的信息对象JSONObject,使用的同一个对象,虽然重新set了值,但还是返回了相同的对象。
JSONObject jsonObject = new JSONObject();
jsonObject.put("state" , 1);
jsonObject.put("wxUserInfo" , invite);
jsonObject.put("questions" , questions);
jsonObject.put("pkId" , pkGroup.getId());
client.sendEvent("ConnectReceive",jsonObject);
SocketIOClient socketIOClient = clientMap.get(inviteUsrEntId);
WxUserInfo accept = wxUserInfoMapper.queryWxUserInfoByUsrEntId(usrEntId);
jsonObject.put("state" , 1);
jsonObject.put("questions" , questions);
jsonObject.put("pkId" , pkGroup.getId());
jsonObject.put("wxUserInfo" , accept);
socketIOClient.sendEvent("ConnectReceive" , jsonObject);

后改为重新new一个JSONObject对象,问题解决。

2、本地测试没问题,上了测试环境出现问题。连接时间超过1分钟,会自动断开连接。

后经查是服务器使用了nginx,nginx默认连接60s会断开连接。

需更改nginx配置,如下:

location /socket.io {
proxy_pass http://172.17.0.2:9999;
proxy_set_header Host $host;
proxy_next_upstream off;
proxy_buffering off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 3600s;
}
proxy_read_timeout默认为60s,若需要长时间连接,改大点。
   三、前端代码示例
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.3.0/socket.io.js"></script>
<script type="text/javascript">
const connectEvent = "ConnectReceive";
const aiEvent = "AIReceive";
const challengeEvent = "challengeReceive";
const sendEvent = "ServerReceive";
const againEvent = "AgainReceive";
const clientEvent = "ClientReceive";
const skillEvent = "SkillReceive";
var socket;
function socketClick() {
//连接服务器,返回房间、题目信息
socket = io.connect('http://127.0.0.1:9999', {
'force new connection': true,
'query': 'usrEntId=' + 41 + '&type=' + 1
})
 
socket.on(connectEvent, function (data) {
//data:{pkId: 31,state: 0} 房间号、状态为0表示创建了个房间,为1表示有房间并已加入
//data:{pkId: 31,questions:[{},{}...],state: 1,wxUserInfo:{openId:,unionId:,nickName:,headImg:,empiricalValue:,usrEntId:,createTime:,medal:}}
console.log(data)
})
 
socket.on(clientEvent, function (data) {
//data:{disconnect: 1} 对手退出了房间
console.log(data)
})
 
socket.on(skillEvent, function (data) {
//data:{usrEntId:42 , skill: 1 , info:1} 对手id、使用了技能,技能id
console.log(data)
})
 
socket.on(aiEvent, function (data) {
//data:{pkId: 31,questions:[{},{}...],state: 1} 房间号、题目集合、状态
console.log(data)
})
 
//每道题答完接收消息
socket.on(challengeEvent, function (data) {
//返回 data:{pkId: 31,winUsrEntId: 41,usrEntId:42,answer:1,time:3} 房间号、赢家id、对手id、答案1对0错、时间
console.log('ServerReceive成功')
})
 
socket.on(againEvent, function (data) {
//data:{state: 0,usrEntId: 41} state为0邀请信息、邀请再来一局玩家id
//data:{state: 1,wxUserInfo: {},questions:[{},{}...],pkId} state为1再来一局成功、对手信息、题目、房间号
console.log(data)
})
 
socket.on(clientEvent, function (data) {
//data:{disconnect: 1} 对手退出了房间
console.log(data)
})
 
//发送和人机pk消息到服务器
send({
action: 'getAI',
usrEntId: 41
})
 
//每道题答完发送消息到服务器
send({
action: 'challenge',
usrEntId: 41,
answer: 1,
time: 6,
pkId: 1,
orderNum: 1,
queResId: 1,
option: 3
})
//再来一局
send({
action: 'again',
usrEntId: 41,
pkId:1
})
 
//发送技能
send({
action: 'skill',
usrEntId: 41,
pkId:1
})
 
}
function send(data){
socket.emit(sendEvent,data);
}
 
function quitClick() {
var data={usrEntId:41};
socket.disconnect();
}
</script>

 

おすすめ

転載: blog.csdn.net/m0_64355285/article/details/121771893