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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Websocket + Webserver on same Domain question

  • 07-04-2014 10:22am
    #1
    Registered Users, Registered Users 2 Posts: 3,888 ✭✭✭


    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, Registered Users 2 Posts: 2,763 ✭✭✭Sheeps


    Can you try binding the websocket to a different port?


  • Registered Users, Registered Users 2 Posts: 27,370 ✭✭✭✭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, Registered Users 2 Posts: 3,888 ✭✭✭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