[TIMOB-10836] BlackBerry: Socket connected callback is not actually called
| GitHub Issue | n/a |
|---|---|
| Type | Bug |
| Priority | Medium |
| Status | Closed |
| Resolution | Cannot Reproduce |
| Resolution Date | 2013-08-09T17:27:28.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | 2013 Sprint 16, 2013 Sprint 16 API |
| Components | BlackBerry |
| Labels | n/a |
| Reporter | Hayk Zakaryan |
| Assignee | Pedro Enrique |
| Created | 2012-09-11T04:22:17.000+0000 |
| Updated | 2017-03-08T18:52:28.000+0000 |
Description
When creating client socket and providing 'connected' callback function is not called actually.
Example code can be found in KitchenSink Resources\ui\common\platform\socket_connect.js
connectButton.addEventListener part.(~line 120)
connectingSocket = Ti.Network.Socket.createTCP({
host:hostField.value,
port: parseInt(portField.value),
connected:function(e) {
e.socket.write(Ti.createBuffer({value:"Well, hello there!"}));
Ti.Stream.pump(e.socket,pumpCallback,1024, true);
},
error:function(e) {
statusArea.value = "ERROR ("+e.errorCode+"): "+e.error;
},
closed:function(e) {
statusArea.value = "CLOSED CONNECTION TO: "+e.socket.host+":"+e.socket.port;
}
});
connectingSocket.connect();
For testing added simple alert in the connected callback function and it did not appeared.
Before that started a listener in my computer - port 40405.
opened the KS app Platform->Sockets->Connecting socket. Typed host 127.0.0.1 port 40405 and clicked connect button.
Listener Socket mentioned that client connected but actual connected callback didn't worked on the simulator
In order for the port to be correct - port value should be parsed to Number as - port: parseInt(portField.value),
(not as port:portField.value - in KS original version).
Tested on device. Connected computer to the same wifi network as the device. Got IP address. Created a node.js proxy server on port 9999. Tested sample app. It worked fine.
node.js
var net = require('net'); net.createServer(function(socket) { socket.on('data', function(buffer) { var str = buffer.toString('ascii'); var arr = str.split('\n'); if(arr.length > 1) { for(var i = 0, len = arr.length - 1; i < len; i++) { console.log('[INFO] ' + arr[i]); } } else { console.log('[INFO] ' + str); } }); socket.on('end', function() { console.log('end'); }); }).listen(9999);app.js
Ti.UI.setBackgroundColor('white'); var win = Ti.UI.createWindow({ }); var btn = Ti.UI.createButton({ bottom: 0 }); win.add(btn); btn.addEventListener('click', function(e){ var clientSocket = Ti.Network.Socket.createTCP({ host : '172.16.0.115', port : 9999, connected : function(e) { Ti.API.info('Client socket connected!'); Ti.Stream.pump(e.socket, pumpCallback, 1024, true); e.socket.write(Ti.createBuffer({ value : 'A message from a connecting socket.' })); }, error : function(e) { Ti.API.info('Error (' + e.errorCode + '): ' + e.error); } }); clientSocket.addEventListener('connected', function(e){ Ti.API.info('Connected!!!!!!!'); Ti.API.info(e); e.socket.write(Ti.createBuffer({ value : 'Connected' })); }); function writeCallback(e) { Ti.API.info('Successfully wrote to socket.'); } function pumpCallback(e) { // Has the remote socket closed its end? if (e.bytesProcessed < 0) { Ti.API.info("Closing client socket."); clientSocket.close(); return; } try { if(e.buffer) { var received = e.buffer.toString(); Ti.API.info('Received: ' + received); } else { Ti.API.error('Error: read callback called with no buffer!'); } } catch (ex) { Ti.API.error(ex); } } clientSocket.connect(); }); win.open();Closing ticket as the issue cannot be reproduced.