0

I'm getting started with node.js and socket.io, all the tutorials that I've found online suggest using this In the client side code.

<script type="text/javascript" src="http://localhost:3000/socket.io/socket.io.js" ></script>

var socket = io.connect('localhost:3000');

This works fine if client runs on the same host. I'm trying to write an app where client can connect through some other host. How do I do that?

I know I can use ip address of host instead of "localhost" for this purpose but I want to know if there is more generic way of doing this so that the code is host independent.

4

1 回答 1

3

只需使用相对路径。

var socket = io.connect('/');

Socket.io 将连接到加载页面本身的主机和端口。

于 2013-11-12T19:31:44.930 回答