I am using socket.io on the client and I want to start a connection from the client to a server that runs node with socket.io installed.
Is this possible? Cat I do this using socket.io-client?
This is my code
CLIENT
<script src="http://cdnjs.cloudflare.com/ajax/libs/socket.io/1.4.5/socket.io.js"></script> <script> var socket = io.connect("localhost:8001") </script>
In the browser console I get the following error
GET http://file/socket.io/?EIO=3&transport=polling&t=LF7pj8U net::ERR_NAME_NOT_RESOLVED
SERVER
var http = require("http")
var io = require('socket.io')
var server = http.createServer(function(req, res){
})
server.listen(8001)
If the socket.io server is not the same node instance than the http server you'll need to instanciate socket service like this :
var io = require('socket.io')();
io.listen(8001);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.