简体   繁体   English

android 浏览器和 socket.io

[英]android browser and socket io

I having trouble getting socket.io to send a response on connect for the android browser.我无法让 socket.io 为 android 浏览器发送连接响应。 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.我禁用了 jsonp,但我听说 android 无论如何都会退回到 xhr。

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).这适用于所有浏览器(甚至移动 safari、移动 FF、移动 chrome beta)。 I have to refresh android browser 4-5 times for it to finally connect.我必须刷新 android 浏览器 4-5 次才能最终连接。 BTW, im using streamline js (_)顺便说一句,我正在使用 streamline js (_)

UPDATE This seems to happen on wifi only更新这似乎只发生在 wifi 上

Limited options at this time:目前有限的选择:

http://code.google.com/p/weberknecht/ http://code.google.com/p/weberknecht/

https://github.com/TooTallNate/Java-WebSocket https://github.com/TooTallNate/Java-WebSocket

https://github.com/Gottox/socket.io-java-client 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.就 WebSockets go 而言听起来不错。Socket.IO 的特定线路协议似乎尚未在 Java 中实现,因此您可能必须自己处理。

Following the socket.io website , it seems you are not using it right.关注了socket.io网站,看来你没用对。

Try changing socket.on('connect',function (data) {尝试更改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.对于它的价值,下面这个简单的例子适用于我的 Android 浏览器。 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 :让我们知道您是否需要任何特定的东西,下面没有涵盖——重要:将 IP 号码和端口更改为适合您环境的任何内容

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM