[英]node.js create 'server side socket' for bots chat (chatscript)
We're using Socket.io's socket.emit and socket.on methods to manage chatroom messages. 我们正在使用Socket.io的socket.emit和socket.on方法来管理聊天室消息。
var io = require('socket.io') // socket.io.js
var sio = io.listen(server);
app.set('socket io', sio);
sio.sockets.on('connection', function (socket) {
socket.on('broadcast-message', function(chatroomIdStr, username, message) {
});
}):
On the client side we have : 在客户端,我们有:
socket.emit("broadcast-message", chatroomId, username, message);
We're using Chatscript and wanted to use the same schema for sending bot messages. 我们正在使用Chatscript,并希望使用相同的架构来发送漫游器消息。 However, when trying this on the server side (app.js) : 但是,在服务器端(app.js)尝试此操作时:
var socketbot = io.connect('localhost')
socketbot.emit("broadcast-message", chatroomId, username, message);
We get: 我们得到:
TypeError: Object # has no method 'connect' TypeError:对象#没有方法“连接”
Any ideas on this? 有什么想法吗?
I'm working on something similar and believe the answer is that you need to use 'socket.io-client' in your nodejs bot rather than 'socket.io'. 我正在研究类似的东西,并且相信答案是您需要在nodejs机器人中使用“ socket.io-client”而不是“ socket.io”。
'npm install socket.io-client' got me something I could work with, but I'm still debugging what the bot client should look like. 'npm install socket.io-client'使我可以使用某些东西,但是我仍在调试bot客户端的外观。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.