Connecting client to server using Socket.io

前端 未结 2 466
情深已故
情深已故 2021-01-29 22:18

I\'m relatively new to node.js and it\'s addons, so this is probably a beginnersquestion.

I\'m trying to get a simple HTML page on a webserver connect to a different ser

2条回答
  •  既然无缘
    2021-01-29 22:44

    Have you tried loading the socket.io script not from a relative URL?

    You're using:

    
    

    And:

    socket.connect('http://127.0.0.1:8080');
    

    You should try:

    
    

    And:

    socket.connect('http://localhost:8080');
    

    Switch localhost:8080 with whatever fits your current setup.

    Also, depending on your setup, you may have some issues communicating to the server when loading the client page from a different domain (same-origin policy). This can be overcome in different ways (outside of the scope of this answer, google/SO it).

提交回复
热议问题