我有以下内容,使用NodeJS与Express进行简单的服务器和客户端连接:
var express = require('express');
var http = require('http')
var socketio = require('socket.io');
var app = express();
var server = http.Server(app);
var websocket = socketio(server);
server.listen(3000, () => console.log('Listening to: 3000'));
// The event will be called when a client is connected.
websocket.on('connection', (socket) => {
console.log('Client just joined with ', socket.id);
});
和:
import React from 'react';
import SocketIOClient from 'socket.io-client';
class Main extends React.Component {
constructor(props) {
super(props);
// Creating the socket-client instance will automatically connect to the server.
this.socket = SocketIOClient('http://localhost:3000');
}
}
module.exports = Main;
只需要两个人之间的聊天室,以及包含持久消息的聊天室列表。
但我已将项目与Sails.js
集成,并想知道我应该如何使用Socket.io
处理它?</ p>
提前感谢您,一定要投票/接受回答