Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Websocket + Webserver on same Domain question

Options
  • 07-04-2014 11:22am
    #1
    Registered Users Posts: 3,853 ✭✭✭


    Summary: Chrome doesn't seem to want to send out a websocket request to the same domain as the page was loaded from


    Question:
    I have coded up a small html & websocket server on a small device -

    It runs on ip/port 192.168.1.100:8080 and will deliver a small webpage - that page makes a Websocket connection to the same device (ie. again 192.168.1.100:8080) for updates -

    Think like the Web admin page of a typical modem.


    The device correctly responds to separate html or websocket requests on the same port ok.


    But I'm having an issue with connections from the browser - the page downloads but Chrome doesn't seem to want to send out a websocket request to the same domain as the page was loaded from.

    However...
    If I create a HOSTS alias for the IP address - called eg. (panel = 192.168.1.100). And I browse to

    http://panel:8080

    the page downloads and websocket connects successfully to http://192.168.1.100:8080 (ie. the same device)

    All works -

    But if I try to connect directly using an IP
    http://192.168.1.1:8080

    The HTML page downloads - but chrome silently refuses to connect to the websocket this time.



    Is this normal behaviour for websockets - and would anyone have any ideas to bypass it? I don't wan't users to have modify the HOSTS file like this to get it to work.
    The device is very limited and would have problems hosting Two separate servers on different ports.
    Thanks.

    “Roll it back”



Comments

  • Registered Users Posts: 2,762 ✭✭✭Sheeps


    Can you try binding the websocket to a different port?


  • Registered Users Posts: 27,073 ✭✭✭✭GreeBo


    If i understand correctly the webserver is running on the device itself....have you tried localhost:8080 or 127.0.0.1:8080


  • Registered Users Posts: 3,853 ✭✭✭ozmo


    Sheeps wrote: »
    Can you try binding the websocket to a different port?

    Thanks - yes - tried a few eg. 8080 and 80.
    GreeBo wrote: »
    If i understand correctly the webserver is running on the device itself....have you tried localhost:8080 or 127.0.0.1:8080

    So the device (An Arduino) is eg. 192.168.1.100(configurable) and has webserver and websocket server on port 8080 (configurable) - and Im connecting from a PC on same lan - but different IP.

    When the websocket in the html page is to connect to a different domain (ip:port)to where the html page came from it works - but when the the socket is to connect to a same domain (ip:port) as the html page came from it does not work (the browser does not attempt at all to send a websocket request).


    Im trying get it all on the same box - just like the web admin page of a router etc. thanks.

    “Roll it back”



Advertisement