基本上,我正在尝试将我的聊天服务器应用程序部署到Heroku上,然后通过命令'heroku labs:enable websockets'启用了Web套接字
我觉得我的Procfile错了......我认为让它进行网络处理是错误的。
web: node app.js
继续,我需要托管我的ChatServer ,并能够通过 telnet 连接到它。过去2个小时我一直试图这样做。帮助plssss!
var net = require('net')
var Parser = require('./Parser')
var Writer = require('./Writer')
var Broadcaster = require('./Broadcaster')
var Room = require('./Room')
var SocketUsername = require('./SocketUsername')
var Command = require('./Command')
var RoomHelper = require('./RoomHelper')
var server = net.Server()
server.listen(1337)
var sockets = []
var rooms = []
var DEFAULTROOM = "home"
rooms.push(new Room(DEFAULTROOM))
server.on('connection', function(socket) {
socket.room = DEFAULTROOM
sockets.push(socket)
Writer.greet(socket)
Writer.askName(socket)
socket.on('data', respondToUserInput)
socket.on('end', removeSocket)
})
function removeSocket() {
var i = sockets.indexOf(this)
sockets.splice(i, 1)
}
function respondToUserInput(data) {
var currentSocket = this
var userInput = data.toString().trim()
if (currentSocket.username) {
var parsedInput = Parser.analyzeInput(userInput)
if (Command.isValid(parsedInput["command"])) {
Command.execute(parsedInput, currentSocket, rooms, sockets)
}
if (parsedInput["dialog"]) {
Broadcaster.postDialog(currentSocket, userInput, sockets)
}
} else {
if (SocketUsername.isAvailable(userInput, sockets) && SocketUsername.isValid(userInput)) {
SocketUsername.assign.call(currentSocket, userInput)
Writer.welcomeUser(currentSocket, currentSocket.username)
Broadcaster.announceEnteredRoom(currentSocket, sockets)
} else {
Writer.notifyNameInvalid(currentSocket)
}
}
}