android browser and socket io
I having trouble getting socket io to send a response on connect for the android browser. I logged the parameters and they are appearing server side, it just seems like that the client side doesn't properly connnect. I disabled jsonp, but I heard that android falls back to xhr anyways.
socket.on('connect',function (data) {
socket.emit('setNickAndRoom', {nick: nick}, function(response){
//response. nothing :(.
});
});
client.on("setNickAndRoom", function(nick, fn,_){
//etc etc
fn({msg :nick});
});
This works on every browser (even mobile safari, mobile FF, mobile chrome beta). I have to refresh android browser 4-5 times for it to finally connect. BTW, im using streamline js (_)
UPDATE This seems to happen on wifi only
Limited options at this time:
http://code.google.com/p/weberknecht/
https://github.com/TooTallNate/Java-WebSocket
https://github.com/Gottox/socket.io-java-client
sound right as far as WebSockets go. Socket.IO's specific wire protocol do not appear to have been implemented in Java yet, so you may have to deal with that yourself.
Following the socket io website, it seems you are not using it right.
Try changing socket.on('connect',function (data) {
to
socket.on('connection',function (data) {
For what it's worth, this simple example below works on my Android browser. Let us know if there's anything specific you need, that's not covered below -- important: Change the IP number and port to whatever fits your environment:
var express = require('express'),
socketio = require('socket.io'),
app = express.createServer(),
io = socketio.listen(app);
var index = "<!doctype html>
<html>
<head>
<script src=/socket.io/socket.io.js></script>
<script>
var socket = io.connect('http://10.0.1.29:3000');
function send() {
socket.emit('foo', 'Ben', function(data) {
alert(data);
});
}
</script>
</head>
<body>
<button onclick='send();'>Send</button>
</html>";
app.get('/', function(req, res) {
res.send(index);
});
io.sockets.on('connection', function(socket) {
socket.on('foo', function(name, f) {
f('Hello ' + name);
});
});
app.listen(3000);
链接地址: http://www.djcxy.com/p/58860.html
上一篇: 关于PHP中的if语句
下一篇: android浏览器和socket io