javascript - 节点JS | 在服务器中使用两个协议
问题描述
我想在我的服务器上使用 http 协议和 websocket,我将解释:
我有一个聊天应用程序,我有一个登录页面和聊天页面。我想在登录页面上使用 http 协议,在聊天页面上使用 websocket。
如果答案是肯定的,我可以这样做吗?
const express = require('express')
const http = require('http')
const app = express()
const server = http.createServer(app)
const io = socketio(server)
in.on('connection', (req,res) => {
//...
})
app.get('/',(req,res) => {
//...
})
server.listen(port, (req, res) => {
console.log('Server is listen on port ' + port)
})
解决方案
推荐阅读
- javascript - javascript中带有百分比值的图表
- azure-data-explorer - 了解 Kusto 表是否覆盖了缓存/保留策略
- c# - 如何捕获正确的异常?
- python - 在python的stdout中搜索字符串
- html - 如何给引导列背景图像?
- typescript - 如何将字符串索引签名添加到现有数组?
- python - 在 Python 3.7 中使用海象运算符
- javascript - React 中的加载屏幕不会渲染
- reactjs - React.useCallback() 仍在重新渲染子组件
- mysql - 使用sql(laravel / mysql)计算一行中的最大重复次数