web sockets

973 views
Skip to first unread message

Dirk Ortolf

unread,
Oct 11, 2012, 7:40:38 AM10/11/12
to comman...@googlegroups.com
Hi,

I have interact with a Loxone Miniserver. This server has an built in websocket server.

Is it possible to open an websocket with iViewer over JavaScript?

vmailtk5

unread,
Oct 11, 2012, 7:41:55 AM10/11/12
to comman...@googlegroups.com
yes


--
You received this message because you are subscribed to the Google Groups "CommandFusion Software" group.
To view this discussion on the web visit https://groups.google.com/d/msg/commandfusion/-/OhdHZzTFed4J.
To post to this group, send email to comman...@googlegroups.com.
To unsubscribe from this group, send email to commandfusio...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/commandfusion?hl=en.

Jarrod Bell

unread,
Oct 11, 2012, 7:53:18 AM10/11/12
to comman...@googlegroups.com
Yes, see the docs here:
http://www.commandfusion.com/docs/scripting/net.html#cF.request

Regards,

Jarrod Bell
CommandFusion
www.commandfusion.com


Hades

unread,
Oct 11, 2012, 8:41:05 AM10/11/12
to comman...@googlegroups.com
Thanks a lot.

Florent Pillet

unread,
Oct 11, 2012, 9:12:32 AM10/11/12
to comman...@googlegroups.com
Yes you can, but don't use CF.request() if you want to use true websockets.

Instead, use the actual HTML5 websocket interface that you can access from your
iViewer Javascript code. It is the exact same interface that you use from HTML pages,
therefore you can do a:

var socket = new WebSocket("ws://192.168.0.100");
socket.onopen = function() {
// your code here
};
socket.onmessage = function(msg) {
// process received data here
};
socket.onclose = function() {
// process close here
};
socket.onerror = function(err) {
// process error here
};


Florent


On Oct 11, 2012, at 1:40 PM, Dirk Ortolf <dirk....@gmail.com> wrote:

> I have interact with a Loxone Miniserver. This server has an built in websocket server.
>
> Is it possible to open an websocket with iViewer over JavaScript?

--
Florent Pillet - Software Engineering Lead
www.commandfusion.com



Hades

unread,
Oct 11, 2012, 9:31:24 AM10/11/12
to comman...@googlegroups.com
okay, I tried this.

I just had a problem with this, because the server wants a username and a password and I don't have a clue how i give it to the websocket, before it connects. I think these informations is sent in the URI. But I think that's a problem Loxone can help me.

vmailtk5

unread,
Oct 11, 2012, 9:35:20 AM10/11/12
to comman...@googlegroups.com
you send it to the socket, use wireshark to see what data is being passed through

--
You received this message because you are subscribed to the Google Groups "CommandFusion Software" group.
To view this discussion on the web visit https://groups.google.com/d/msg/commandfusion/-/RkC3FcaGOBUJ.

Hades

unread,
Oct 12, 2012, 2:36:32 AM10/12/12
to comman...@googlegroups.com
As I understood the username and password is needed for the Handshake. So it has to be in the Header of the Websocket.

Nadim Awan

unread,
Oct 12, 2012, 4:34:03 AM10/12/12
to comman...@googlegroups.com
No, there's no header, you just send it

Sent from my iPhone

On 12 Oct 2012, at 07:36, Hades <dirk....@gmail.com> wrote:

> As I understood the username and password is needed for the Handshake. So it has to be in the Header of the Websocket.
>
> --
> You received this message because you are subscribed to the Google Groups "CommandFusion Software" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/commandfusion/-/KEOYrzoSUzAJ.

Steve

unread,
Oct 12, 2012, 9:08:23 AM10/12/12
to comman...@googlegroups.com
Have you tried var socket = new WebSocket("ws://username:password@192.168.0.100");

Hades

unread,
Oct 12, 2012, 10:45:52 AM10/12/12
to comman...@googlegroups.com
I tried this. This did not work.

vmailtk5

unread,
Oct 12, 2012, 10:46:47 AM10/12/12
to comman...@googlegroups.com
what data you you get with wireshark?

--
You received this message because you are subscribed to the Google Groups "CommandFusion Software" group.
To view this discussion on the web visit https://groups.google.com/d/msg/commandfusion/-/xKSbNwGxmJ4J.

Hades

unread,
Oct 12, 2012, 12:15:18 PM10/12/12
to comman...@googlegroups.com
The problem was, that I can't log any WIFI-data with wireshark.

So I created a little web page which connected to the server.

I successfully connected to the server by appending the "username:password"-phrase, which has to be base64 encoded, at the URL. So my code looks like this:

ws = new WebSocket("ws://192.168.0.100/ws/dXNlcjpwYXNzd29yZA==");
 
this works fine on my web page but on CommandFusion the Socket will be instantly closed.

The data which i sended with my web page is:

Hypertext Transfer Protocol
    GET /ws/dXNlcjpwYXNzd29yZA== HTTP/1.1\r\n
        [Expert Info (Chat/Sequence): GET /ws/dXNlcjpwYXNzd29yZA== HTTP/1.1\r\n]
        Request Method: GET
        Request URI: /ws/dXNlcjpwYXNzd29yZA==
        Request Version: HTTP/1.1
    Upgrade: websocket\r\n
    Connection: Upgrade\r\n
    Host: 192.168.3.47\r\n
    Origin: null\r\n
    Sec-WebSocket-Key: SJLkEjbVkAIFbHUy3PevLA==\r\n
    Sec-WebSocket-Version: 13\r\n
    Sec-WebSocket-Extensions: x-webkit-deflate-frame\r\n
    Cookie: devs=07216600960119371998_admin\r\n 

the data which i received from the server is:
Hypertext Transfer Protocol
    HTTP/1.1 101 Web Socket Protocol Handshake\r\n
        [Expert Info (Chat/Sequence): HTTP/1.1 101 Web Socket Protocol Handshake\r\n]
        Request Version: HTTP/1.1
        Status Code: 101
        Response Phrase: Web Socket Protocol Handshake
    Upgrade: WebSocket\r\n
    Connection: Upgrade\r\n
    Sec-WebSocket-Origin: null\r\n
    Sec-WebSocket-Location: ws://192.168.3.47/ws/YWRtaW46YWRtaW4=\r\n
    Sec-WebSocket-Accept: UuPU0iQS+5gUdiA2Jp2enLurhbc=\r\n
    \r\n

With CommandFusion, I can't say how the connection establishes, because of the WIFI-problem with wireshark. I think I try to fix this in the next days and post my progress here.

btw I'd like to thank you for the great help! 

Am Donnerstag, 11. Oktober 2012 13:40:38 UTC+2 schrieb Hades:

Florent Pillet

unread,
Oct 13, 2012, 2:08:26 AM10/13/12
to comman...@googlegroups.com
Set up your iPad to use your desktop computer as an HTTP proxy. Since WebSockets run over HTTP
connections, they will be proxied too.

Use Charles Proxy to intercept traffic and log it. Get it here: http://www.charlesproxy.com/

It's a tool everyone should have in their toolchest.

Florent

Hades

unread,
Oct 13, 2012, 5:58:26 PM10/13/12
to comman...@googlegroups.com
Thanks for the tip. I'll try it tomorrow.

Hades

unread,
Oct 15, 2012, 4:27:53 AM10/15/12
to comman...@googlegroups.com
So I figured out what CommandFusion sends and what the Miniserver responds.

The request header looks like this:
 
GET /ws/dXNlcjpwYXNzd29yZA== HTTP/1.1
Upgrade: WebSocket
Connection: Upgrade
Host: 192.168.0.1000
Origin: file://
Sec-WebSocket-Key1: N26  0Lm7:PH7+p   p  7nt16  2 0
Sec-WebSocket-Key2: 299 8"a72 056    8  I

And the server responses with:
 HTTP/1.1 401 Unauthorized
Server: Loxone 3.14.9.17
WWW-Authenticate: Basic realm="ws"
Content-Type: text/html
Content-Length: 93
Connection: close

<html><head><title>Loxone Miniserver error</title></head><body>401 Unauthorized</body></html>

So I have to find out on which way I have to authenticate. I'm surprised, because the js-code of my little site i wrote is exactly the same and there it works :o 

Jarrod Bell

unread,
Oct 15, 2012, 9:04:03 AM10/15/12
to comman...@googlegroups.com
Have you logged in to the page on your site before it works? Sounds like you just need to add BASIC auth headers.


Regards,

Jarrod Bell
CommandFusion
www.commandfusion.com


--
You received this message because you are subscribed to the Google Groups "CommandFusion Software" group.
To view this discussion on the web visit https://groups.google.com/d/msg/commandfusion/-/XyDRMxUq8UYJ.

Hades

unread,
Oct 15, 2012, 10:13:47 AM10/15/12
to comman...@googlegroups.com, jar...@commandfusion.com
Yes you*re right. This was my fault.

Now I'm doing two things to get the web socket first I send an HTTP request with the user credentials, if this works I open the web socket.

I think this is a quick'n'dirty solution but it works. I'll optimize that later.

Thank you all for your great help :)

Hades

unread,
Nov 15, 2012, 6:57:23 AM11/15/12
to comman...@googlegroups.com, jar...@commandfusion.com
after a month of silence in this post i have another question about websockets. I am testing my gui every time in debug mode and made real good progress. last week i tested the first time without debugger and gui crashed nearly instantly as i opened the web socket.

I was really confused, because all the time with the debugger it worked fine. Besides I'm developing all this as webApp and there it works perfect.

Now I isolated the central part "websocket" and wrote a little js-file and a little html-file for testing. These files can be seen here.

I have no clue what I'm doing wrong and hope someone can help me.

Jarrod Bell

unread,
Nov 15, 2012, 9:52:39 PM11/15/12
to comman...@googlegroups.com
Have you tried running your HTML version in safari on the iPad?

In debug mode, all the scripting is run in the desktop browser, whilst otherwise its run in the mobile browser - so there are most likely some differences in new browser functionality like web sockets.

If you can also send us the crash logs, it would be helpful:
http://www.commandfusion.com/wiki2/software/iviewer/crash-logs


Regards,

Jarrod Bell
CommandFusion
www.commandfusion.com


To view this discussion on the web visit https://groups.google.com/d/msg/commandfusion/-/xJJtNoGJgroJ.

Hades

unread,
Nov 16, 2012, 5:12:49 AM11/16/12
to comman...@googlegroups.com
I haven't tried my html version on safari. I probably can test this earliest next monday.

I actually looked at the last crash log. This log is in my temp_depot (see link in my last post).

Is it possible for me as a newbie to interpret that? What I can see in this log are the running threads, the thread which run in the exception and the register values of this thread. I'm unfortunately not so familiar with that matter.

Am Donnerstag, 11. Oktober 2012 13:40:38 UTC+2 schrieb Hades:

Florent Pillet

unread,
Nov 16, 2012, 5:58:25 AM11/16/12
to comman...@googlegroups.com
Nope you can't interpret it, but we're looking into it. Thanks for making it and the source code available.

Florent

Florent Pillet

unread,
Nov 16, 2012, 7:30:36 AM11/16/12
to comman...@googlegroups.com
We looked into your issue and found websockets to work perfectly fine. We tried:

- connecting to a Socket.io server and exchanging messages
- connecting to a straight websocket server with the code you provided (just swapped in different connection URL for the ws connection and CF.request), the websocket server serving back a JSON with the expected data. Again, this works fine.

One thing that appears from your crash log is that it is the low level JS engine in iOS that is crashing, and it seems to be on a setInterval() call. But I don't see any setInterval() in the code you shown. Could you be using a different code on your side that you have not shown in your example?

Our tests were run on iOS 6.0.1 on an iPad 2 so it's a setup pretty similar to yours. We don't have a Loxone miniserver for testing.

Could you email me a full GUI that exhibits your issue? There may be other environmental factors leading to the crash that we didn't reproduce here.

Florent

On Nov 16, 2012, at 11:12 AM, Hades <dirk....@gmail.com> wrote:

Hades

unread,
Nov 16, 2012, 10:58:56 AM11/16/12
to comman...@googlegroups.com
Thanks for the information. I played with this js function. I but I don't know where it will be executed.

Nevertheless I just started a new gui project and the first tests seem to be stable. If you like I can insert the complete gui project on my temp_depot.
Reply all
Reply to author
Forward
0 new messages