현재 데이터베이스 주변에 새로운 활동을위한 푸시 서버 인스턴스를 만들려고합니다. 물론이 주제에 대한 많은 정보를 찾을 수 있습니다.node.js WebSocket Server
내가 사용하고 다음 클라이언트 구현으로 http://static.brandedcode.com/nws-docs/#s6-p1
:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="http://cdn.socket.io/stable/socket.io.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<title></title>
</head>
<body>
<script type="text/javascript">
(function() {
var webSocket = new io.Socket('ws//test', {
port: 8080
});
webSocket.connect();
webSocket.on('connect',function() {
console.log('Client has connected to the server!');
});
webSocket.on('message',function(data) {
console.log('Received a message from the server!',data);
});
webSocket.on('disconnect',function() {
console.log('The client has disconnected!');
});
window.ws = webSocket;
}());
</script>
</body>
</html>
콘솔 반환 :
Unexpected response code: 404
XMLHttpRequest cannot load http://ws//test:8080/socket.io/xhr-polling//1303822796984. Origin http://test is not allowed by Access-Control-Allow-Origin.
1303822796984GET http://ws//test:8080/socket.io/xhr-polling//1303822796984 undefined (undefined)
내가 문제를 모르겠어요.
도움 주셔서 감사합니다.
Greets!