0
를 전송 및/또는 잡하지 채팅 Socket.IO에 : https://www.youtube.com/watch?v=pNKNYLv2BpQ내가 socket.io 채팅 튜토리얼을 따라 한 메시지
를 튜토리얼 비디오에서는 그러나 나의이 전혀 작동하지 않습니다 잘 작동합니다. 메시지는 이것은 내 index.html을 클라이언트
있는 서버 또는이 내 app.js 노드var express = require('express'),
app = express(),
server = require('http').createServer(app),
io = require('socket.io').listen(server);
server.listen(3000);
app.get('/', function(req, res) {
res.sendfile(__dirname + '/index.html');
});
io.sockets.on('connection', function(socket) {
socket.on('send message', function(data) {
io.sockets.emit('new message', data);
});
});
와 서버 측에서 실행되는
클라이언트 중 하나에 의해 전송하거나 수신하지 않는 것
<html>
<head>
<title>Chat with socket.io and node.js</title>
<style>
#chat
{
height: 500px;
}
</style>
</head>
<body>
<div id="chat"></div>
<form id="send-message">
<input size="35" id="message"></input>
<input type="submit"></input>
</form>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
jQuery(function($) {
var socket = io.connect();
var $messageForm = $('#send-message');
var $messageBox = $('#message');
var $chat $('#chat');
$messageForm.submit(function(e) {
e.preventDefault();
socket.emit('send message', $messageBox.val());
$messageBox.val('');
});
socket.on('new message', function(data) {
$chat.append(data + "<br/>");
});
});
</script>
가 나는, 어떤 아이디어를 내가 간과하지만 난 순간 난처한 상황에 빠진거야 간단한 오류가 가정 ??? 추가 정보가 필요한 경우도 그렇게 말하십시오 :
이렇게하면됩니다. var io = require ('socket.io') (server); – nalinc
@NLN 해결책을 찾으면 다음과 같이 나타납니다. /home/snapper26/Desktop/chat/app.js:4 \t io = require ('socket.io') (서버); \t^ TypeError : 개체가 함수가 아닙니다. at Object. (/home/snapper26/Desktop/chat/app.js:4:27) 012. 모듈 확장 모듈 (module.js : 476 : 10) at Module.load (module.js : 356 : 32) Function.Module._load (module.js : 312 : 12) Function.Module.runMain (module.js : 497 : 10) at 시작 (node.js : 119 : 16) at node.js : 906 : 3 –
Snapper26