ccc1.7正式版,其他版本没测试过。问题如下:
服务器端nodejs:
var exp = require(‘express’);
var app = exp();
var http = require(‘http’).Server(app);
var io = require(‘socket.io’)(http);
app.use(exp.static(’/public’));
io.on('connection', function(socket){
console.log('a user ' + socket.id);
socket.emit('connected', 'hello nihao!');
});
http.listen(9000,function(){
console.log('listening on 9000');
})
新建helloword项目,在helloword.js里修改如下:
onLoad: function () {
this.label.string = this.text;
let self = this;
var sk = io.connect('192.168.31.246:9000');
sk.on('connected', function(msg){
self.label.string = 'cccc';
});
},
xcode真机连接后提示如下:
JSB SocketIO.connect method called
Calling native SocketIO.connect method
In the constructor of HttpClient!
JSB SocketIO eventName to: ‘connected’
JS: A: 15.974000000000018ms
2017-12-12 22:31:56.358408+0800 hello_world-mobile[3459:357377] Starting to load http://192.168.31.246:9000/socket.io/1/?EIO=2&transport=polling&b64=true
2017-12-12 22:31:56.592451+0800 hello_world-mobile[3459:357377] Received response from request to url http://192.168.31.246:9000/socket.io/1/?EIO=2&transport=polling&b64=true
2017-12-12 22:31:56.657505+0800 hello_world-mobile[3459:357296]
Websocket Failed With Error Error Domain=SRWebSocketErrorDomain Code=2132 “Received bad response code from server: 400.” UserInfo={NSLocalizedDescription=Received bad response code from server: 400., HTTPResponseStatusCode=400}
Websocket error received: 2
JSB SocketIO::SIODelegate->onClose method called from native
JSB SocketIO::SIODelegate->fireEventToScript method called from native with name ‘disconnect’ data:
disconnect …
2017-12-12 22:31:56.658001+0800 hello_world-mobile[3459:357296] In the destructor of WebSocket-apple (0x1c0234580).
2017-12-12 22:31:56.658258+0800 hello_world-mobile[3459:357296] WebSocketImpl-apple dealloc: 0x1c00a7f80, SRWebSocket ref: 3
请问什么问题?
