XmlHttpRequest, Ajax, need example of communicating with remote device

I've read dozens of articles but still haven't found a working example. I want a web page to communicate with a remote device.

HTML5 Websockets will eventually be the easy solution. But not everything supports that yet.

XmlHttpRequest has the problem of refusing to communicate with a device not in the same domain.

JSONP sounds like the remote device needs to support it. (I think the remote device is supposed to send JavaScript.)

PHP has stream_socket_client which I've actually had success with. However, if the communication gets messed up it doesn't seem to recover and I have to restart the web server to get it to unhang. (Remote device responds with a TCP/IP "Reset", indicating it isn't happy and wants to start over, but it doesn't seem to be happening on the PHP side.)

So, anyone know of any good examples sample working code that actually works and gets around all these little details that make the system not work?

Solution can be Ajax, XmlHttpRequest, PHP sockets, which I've only read I should use stream_socket_client and/or stream_socket_server instead.

Oh that reminds me, in addition to being able to initiate a connection with the remote device and talking to it, and also listening to it to receive any data it might want to send at any time; I also need the remote device to be able to initiate a connection to a server to send an email message or SMS text message whenever it wants to. (That's actually a separate issue I believe.)
deleydSoftware EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GaryCommented:
One of the simpler ways to around the same origin policy is to use a proxy page.
This means instead of calling the remote domain from the browser you call a proxy page on your own server
This proxy page makes the call to the remote server and returns the results to the browser.

JSONP is the other way to do this and will normally work in all cases. jQuery makes this simple by handling the callback for you.

For the rest of your question then sockets is the way to go and makes it a lot easier to maintain persistent connections
There are other alternatives but we are now getting into a very complicated area and cannot be answered in a simple comment
A bit of reading
http://dsheiko.com/weblog/websockets-vs-sse-vs-long-polling
That will give you compatibility behind each option and what is involved.
0
deleydSoftware EngineerAuthor Commented:
Any full working examples I can use as a starting point?
0
GaryCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
What is the remote device?
0
deleydSoftware EngineerAuthor Commented:
"Long Pole". There's the secret phrase that gives me the answers I seek. Thank you!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.