Faye on Android

234 views
Skip to first unread message

Eddy Higgins

unread,
Jun 10, 2011, 10:02:25 AM6/10/11
to Faye users
Hi.
I'm new to Fay, and I can't seem to get a faye client subscription
working with an Android (2.2) client

My test server/client work fine with Chrome/Firefox, but Android
browser fails.

My client is ...
----------8<---------index.html----------8<---------
html><head>
<script type="text/javascript" src="../lib/faye/faye-browser.js"></
script>
<script type="text/javascript">
function init() {
var client=new Faye.Client ("http://multisrv:2030/faye");
var d=document.getElementById('div1');
var subscription=client.subscribe ('/time', function (msg)
{d.innerHTML=msg;});
subscription.callback(function() {
alert('Sub active');
client.publish('/time','Message from client');
});
}
</script>
</head>

<body onLoad="init();">
<div id="div1"></div>
</body></html>
----------8<---------index.html----------8<---------
Server is:
----------8<---------server.js----------8<---------
var http = require('http'),
sys = require('sys'),
faye=require('../lib/faye/faye-node.js');

var bayeux = new faye.NodeAdapter({mount:'/faye',timeout: 45});

// Handle non-Bayeux requests
var server = http.createServer(function(request, response) {
sys.puts(request.method + ' ' + request.url);
if (bayeux.call(request, response)) return;

response.writeHead(200, {'Content-Type': 'text/plain'});
response.write('Hello, non-Bayeux request');
response.end();
});

bayeux.attach(server);
sys.puts('Listening on port 2030');
server.listen(2030);
----------8<---------server.js----------8<---------

Client is sending:

OPTIONS /faye HTTP/1.1
Host: multisrv:2030
Accept-Encoding: gzip
Accept-Language: en-IE, en-US
Access-Control-Request-Headers: Content-Type
x-wap-profile: http://www.htcmms.com.tw/Android/Common/Bravo/HTC_Desire_A8181.xml
Accept-Charset: utf-8, iso-8859-1, utf-16, *;q=0.7
Referer: http://multisrv/WebSandbox/html/
User-Agent: Mozilla/5.0 (Linux; U; Android 2.2; en-ie; Desire_A8181
Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile
Safari/533.1
Origin: http://multisrv
Access-Control-Request-Method: POST
Accept: text/xml, text/html, application/xhtml+xml, image/png, text/
plain, */*;q=0.8
Cache-Control: no-cache
Pragma: no-cache

but server responds with:
--- tcpdump ----
HTTP/1.1 400 Bad Request
Content-Type: text/plain
Connection: keep-alive
Transfer-Encoding: chunked

b
Bad request

Am I doing something silly?
---tcpdump----

Eddy Higgins

unread,
Jun 10, 2011, 10:16:33 AM6/10/11
to Faye users
I should have mentioned...
I'm using 0.6.1, (directly downloaded via http://faye.jcoglan.com/assets/faye.0-6-1.zip)

Regards,
Eddy.

Eddy Higgins

unread,
Jun 10, 2011, 11:41:17 AM6/10/11
to Faye users
I've made some progress with this ...
I fudged faye-node.js to reply to the OPTIONS method ...

--- faye-node.js handle method, line 2193 ---

else if (requestMethod === 'OPTIONS') {
console.log('!OPTIONS');
var headers = {};
headers["Access-Control-Allow-Origin"] = "*";
headers["Access-Control-Allow-Methods"] = "POST, GET, PUT,
DELETE, OPTIONS";
headers["Access-Control-Allow-Credentials"] = false;
headers["Access-Control-Max-Age"] = '86400'; // 24 hours
headers["Access-Control-Allow-Headers"] = "X-Requested-With, X-
HTTP-Method-Override, Content-Type, Accept";
response.writeHead(200, headers);
response.end();

}
--- ---
Now my android browser seems happy to connect.

Regards,
Eddy.


On Jun 10, 3:16 pm, Eddy Higgins <eddy.higg...@gmail.com> wrote:
> I should have mentioned...
> I'm using 0.6.1, (directly downloaded viahttp://faye.jcoglan.com/assets/faye.0-6-1.zip)

Robbie

unread,
Jun 11, 2011, 6:50:38 AM6/11/11
to Faye users
I had the same issue (on Android) and this fixed it.

BTW, Faye is very cool. Great work.

James Coglan

unread,
Jun 11, 2011, 7:32:05 AM6/11/11
to faye-...@googlegroups.com
On 11 June 2011 11:50, Robbie <rob...@robbieallen.com> wrote:
I had the same issue (on Android) and this fixed it.

Thanks for bringing this to my attention, guys. I'll get this merged into a release as soon as I can.

Do you know if this also affects the Ruby version? 

James Coglan

unread,
Jun 12, 2011, 9:34:51 AM6/12/11
to faye-...@googlegroups.com
On 10 June 2011 16:41, Eddy Higgins <eddy.h...@gmail.com> wrote:
--- faye-node.js  handle method, line 2193 ---

else if (requestMethod === 'OPTIONS') {
     console.log('!OPTIONS');
     var headers = {};
     headers["Access-Control-Allow-Origin"] = "*";
     headers["Access-Control-Allow-Methods"] = "POST, GET, PUT,
DELETE, OPTIONS";
     headers["Access-Control-Allow-Credentials"] = false;
     headers["Access-Control-Max-Age"] = '86400'; // 24 hours
     headers["Access-Control-Allow-Headers"] = "X-Requested-With, X-
HTTP-Method-Override, Content-Type, Accept";
     response.writeHead(200, headers);
     response.end();

   }

Can you explain, or point me to docs that explain, what each of these fields is for and why they are all necessary? I know OPTIONS is supposed to return data about the server's capabilities but I want to understand exactly what the response above means for us and how you selected the values.

Eddy Higgins

unread,
Jun 13, 2011, 5:29:56 AM6/13/11
to Faye users
Hi James.
I'm sure you can get away with far fewer headers than I'v put it -
basically I came across this issue before (with tornado perhaps?).
Never
got it resolved properly then and forgot about it.

I reckon that the main header that's required is Access-Control-Allow-
Origin which (by my limited understanding)effectively permits the
subsequent (actual) requests to proceed .

As for the other headers, I'm afraid I just copied them from previous
attempts, so I'm not sure what's required and what isn't.
When I get a chance i'll do some experimenting to see if I can get the
minimal set that works for me.

The specs are in http://www.w3.org/TR/cors/ - though I haven't looked
at these since my previous efforts a while back.

One (unrelated) question - what's the correct way to modify logging
levels - I'm using node, and would like to be able to enable debug
etc. from time to time (and probably use the logging mechanism for my
own additions).

Faye looks really good btw - I just stumbled upon it over the last
week.

Regards,
Eddy.


On Jun 12, 2:34 pm, James Coglan <jcog...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages