微信收费了,自建聊天服务器会不会流行起来
发布于 3 年前 作者 yakczh 3896 次浏览 来自 分享
const app =  require('diet')();
app.listen(8000)
const io = require('socket.io')(app.server)

io.on('connection',  sock => {
 	sock.on('message', msg =>{
           console.log(msg);
           io.sockets.emit("message",msg);
	});
});

app.get('/', function($){
    $.header('content-type', 'text/html');
    $.end( '<!DOCTYPE html>'
        + '<html>'
        + '<head><meta http-equiv="content-type" content="text/html; charset=utf-8">'
        +     '<title>Diet + Socket.io</title>'
        +     '<script src="//cdn.bootcss.com/jquery/3.3.1/jquery.min.js" ></script>'
        +     '<script src="/socket.io/socket.io.js"></script>'
        +     '<script>var socket = io();</script>'
        + '</head>'
        + '<body><input name="msg" id="msg" ><button id="btn">send!</button><ul id="hist"></ul>'
		+     '<script>socket.on("message",function(msg){$("#hist").append("<li>"+msg);});$("#btn").on("click",function(){ socket.send($("#msg").val());$("#msg").val("");});</script>'
        + '</body>'
        + '</html>');
});
 
2 回复

不现实。自己人力也是成本的

自建很快公安局介入,然后就比不过微信了

回到顶部