Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to run a node.js application on my freebsd server, but I can't get the socket.io library to work with it. I've tried including:

    <script src="/socket.io/socket.io.js"></script>

Which gives a 404 error, and if i link directly to the file (i.e. where it is in my public_html folder) I get the io not defined error.

Thanks in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
189 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try creating another node.js application that has this single line in it and then run it with node.js

var io = require('socket.io').listen(8000);

Then in your browser visit http://127.0.0.1:8000 and you should get the friendly "Welcome to socket.io." greeting. If you are getting this then socket.io is running and will serve the socket.io.js file.

The only other thing that I can think of that might be happening is that you might not be linking to the alternate port in your client file. Unless you're running the socket.io server on express which is running on port 80. For now create a client file that has the script source for socket.io set to

<script src="http://127.0.0.1:8000/socket.io/socket.io.js"> </script>

This should connect to the socket.io server running on port 8000 and get the socket.io.js file.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...