How to connect to remote web server from web page

Supporting Browser-based Javascript and Node.js
Post Reply
dhodges47
Phidgetsian
Posts: 6
Joined: Fri Mar 02, 2018 8:01 am
Contact:

How to connect to remote web server from web page

Post by dhodges47 »

Using node, I can connect to a phidget web server running on a raspberry pi from my laptop using this address: phid://raspberry.pi/5661.

However, when I try to connect using javascript using that address, I get an error that says "failed to connect to server".
I also tried ws://raspberrypi.local/phidgets, and I get an error: "Socket error (server unavailable)"

The Phidget control panel application does find the server and accesses the controllers on it. It just seems to be in javascript running in a web page that it can't find it.

The api documentation for javascript doesn't indicate how to open a remote server. So I am stumped. Is this even possible?
mariusz7
Phidgetly
Posts: 18
Joined: Sun Nov 11, 2012 10:51 am
Contact:

Re: How to connect to remote web server from web page

Post by mariusz7 »

You are saying "Using node" - do you mean NodeJS? It IS JavaScript.
You are saying "However... try to connect using javascript" - what do you mean? is it JavaScript on web page?
From my experience using Phidgets JavaScript implementation, it is still in alfa or beta. When you use an example from Phidget API documentation, you will not get error message on server failure because of improper implementation of promise by Phidgets JavaScript API. (The promise is not rejected)
Sorry, I am not helpful, maybe try to use IP address instead of raspberry.pi
Use nmap utility to find IPs on your subnet, example:

Code: Select all

nmap -sn 192.168.1.0/24
User avatar
Patrick
Lead Developer
Posts: 3403
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: How to connect to remote web server from web page

Post by Patrick »

You need to add the port to the hostname. ie:

ws://raspberrypi.local:8989/phidgets

Default port would be 8080 or 8989 for websocket (in browser).


Improvements are on the way to the js library and API documentation later this week.

-Patrick
dhodges47
Phidgetsian
Posts: 6
Joined: Fri Mar 02, 2018 8:01 am
Contact:

Re: How to connect to remote web server from web page

Post by dhodges47 »

Yes, I mean javascript on the web page. NodeJS/Javascript running by itself does connect, but Javascript in the browser doesn't. Yes, I have tried the IP address.
mariusz7 wrote:You are saying "Using node" - do you mean NodeJS? It IS JavaScript.
You are saying "However... try to connect using javascript" - what do you mean? is it JavaScript on web page?
From my experience using Phidgets JavaScript implementation, it is still in alfa or beta. When you use an example from Phidget API documentation, you will not get error message on server failure because of improper implementation of promise by Phidgets JavaScript API. (The promise is not rejected)
Sorry, I am not helpful, maybe try to use IP address instead of raspberry.pi
Use nmap utility to find IPs on your subnet, example:

Code: Select all

nmap -sn 192.168.1.0/24
dhodges47
Phidgetsian
Posts: 6
Joined: Fri Mar 02, 2018 8:01 am
Contact:

Re: How to connect to remote web server from web page

Post by dhodges47 »

Thanks Patrick. I'll try this. And I'll look for the improvements to the js library and documentation.
Patrick wrote:You need to add the port to the hostname. ie:

ws://raspberrypi.local:8989/phidgets

Default port would be 8080 or 8989 for websocket (in browser).


Improvements are on the way to the js library and API documentation later this week.

-Patrick
Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests