最后
编程基础的初级开发者,计算机科学专业的学生,以及平时没怎么利用过数据结构与算法的开发人员希望复习这些概念为下次技术面试做准备。或者想学习一些计算机科学的基本概念,以优化代码,提高编程技能。这份笔记都是可以作为参考的。
开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】
appenders:{
file:{
type:‘file’,
filename:‘app.log’,
layout:{
type:‘pattern’,
pattern:‘%r %p - %m’,
}
}
},
categories:{
default:{
appenders:[‘file’],
level:‘debug’
}
}
});
var logger = log4js.getLogger();
var app=express();
app.use(serveIndex(‘./public’));
app.use(express.static(‘./public’));
//http server
var http_server=http.createServer(app);
//-----------------------------------------------------------------------//
var options={
key:fs.readFileSync(‘./cert/3435783_huangxiaoguo.club.key’),
cert:fs.readFileSync(‘./cert/3435783_huangxiaoguo.club.pem’)
}
//https server
var https_server=https.createServer(options,app);
//命令服务器绑定https
var io = socketIo.listen(https_server);
io.sockets.on(‘connection’,(socket)=>{
logger.debug(“connection”);
//转发信息
socket.on(‘message’, (room, data)=>{
logger.debug("message data “+socket.id+” "+room,data);
socket.to(room).emit(‘message’, room, socket.id, data)//房间内所有人,除自己外
});
//用户加入
socket.on(‘join’,(room)=>{
logger.debug(“join”,",room = “, room,”,socket.id = ", socket.id);
socket.join(room);
var myRoom = io.sockets.adapter.rooms[room];
var users =(myRoom)?Object.keys(myRoom.sockets).length:0;
logger.debug(‘the number of user in room is:’+users)
//处理一对一通信
if (users<USERCOUNT) {
//给本人回信息
socket.emit(‘joined’,room,socket.id);
if(users>1){
socket.to(room).emit(‘otherjoin’,room,socket.id);
}
}else{
socket.leave(room);
socket.emit(‘full’,room,socket.id);
}
//给本人回信息
//socket.emit(‘joined’,room,socket.id);
//给房间除自己以外所有人回
// socket.to(room).emit(‘joined’,room,socket.id);
//给房间所有人回
// io.in(room).emit(‘joined’,room,socket.id);
//除自己所有站点回
// socket.broadcast.emit(‘joined’,room,socket.id)
});
//用户离开
socket.on(‘leave’,(room)=>{
var myRoom = io.sockets.adapter.rooms[room];
var users =(myRoom)?Object.keys(myRoom.sockets).length:0;
//users-1
logger.debug(‘the number of user in room is:’+(users-1));
socket.to(room).emit(‘bye’,room,socket.id);
socket.emit(‘leaved’,room,socket.id);
//给本人回信息
//socket.emit(‘leaved’,room,socket.id);
//给房间除自己以外所有人回
//socket.to(room).emit(‘leaved’,room,socket.id)
//给房间所有人回
//io.in(room).emit(‘leaved’,room,socket.id);
//除自己所有站点回
//socket.broadcast.emit(‘leaved’,room,socket.id)
});
});
https_server.listen(443, ‘0.0.0.0’);
http_server.listen(80,‘0.0.0.0’);
- 页面
Chat Room
connect
Send
- js
‘use strict’
var userName= document.querySelector(‘input#uesrname’);
var inputRoom= document.querySelector(‘input#room’);
var btnConnect= document.querySelector(‘button#connect’);
var outputArea= document.querySelector(‘textarea#output’);
var inputArea= document.querySelector(‘textarea#input’);
var btnSend= document.querySelector(‘button#send’);
var socket ;
var room;
btnConnect.οnclick=()=>{
//链接服务器
socket = io.connect();
//断开服务器
socket.on(‘disconnect’, socket=> {
console.log(“disconnect===>”+socket);
})
//消息
socket.on(‘joined’,(room,id)=>{
btnConnect.disabled=true;
inputArea.disabled=false;
btnSend.disabled=false;
});
socket.on(‘leaved’,(room,id)=>{
btnConnect.disabled=false;
inputArea.disabled=true;
btnSend.disabled=true;
});
socket.on(‘message’,(room,id,data)=>{
console.log(“data====>”+data);
outputArea.scrollTop = outputArea.scrollHeight;//窗口总是显示最后的内容
outputArea.value=outputArea.value+data+‘\r’;
});
//发送消息
room =inputRoom.value;
最后
前端CSS面试题文档,JavaScript面试题文档,Vue面试题文档,大厂面试题文档
开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】
e.log(“data====>”+data);
outputArea.scrollTop = outputArea.scrollHeight;//窗口总是显示最后的内容
outputArea.value=outputArea.value+data+‘\r’;
});
//发送消息
room =inputRoom.value;
最后
前端CSS面试题文档,JavaScript面试题文档,Vue面试题文档,大厂面试题文档
开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】
[外链图片转存中…(img-8uviZExS-1714921905145)]
[外链图片转存中…(img-RHtp56Lr-1714921905146)]