Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-7682] Android: "timeout" property on HTTPClient should only set a connect timeout

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-03-07T11:09:51.000+0000
Affected Version/sn/a
Fix Version/sSprint 2012-05, Release 2.0.0
ComponentsAndroid
Labelsmodule_network, parity, qe-port
ReporterMarshall Culpepper
AssigneeMarshall Culpepper
Created2012-02-16T07:54:57.000+0000
Updated2012-03-19T12:09:03.000+0000

Description

Currently in iOS, the "timeout" property only affects the socket connect, but in Android it affects both the socket connect and socket read. Removing the latter would improve our parity. We may also want to further investigate a "soTimeout" property to keep the read timeout behavior. Test Case:
var socket = Ti.Network.Socket.createTCP({
    host: "some_existing_host",
    port: 50000,
    connected: function(e) {
        Ti.API.info("connected");
    },
    closed: function(e) {
       Ti.API.info("Socket closed");
    },
    error: function(e) {
        Ti.API.info(">> Socket error:" + e.error);
    }
});

socket.timeout = 10000;
socket.connect();
Test Server:
#! /usr/bin/env ruby

require "socket"
serv = TCPServer.open(50000)
nsock = select([serv])
sock = serv.accept
p sock
sleep(10*60)

If a connection to this script is accepted, "#TCPSocket:0x?????" will be displayed, and just wait 10 minutes without read/write. like this:

$ ruby socket_connnect.rb
#TCPSocket:0x105a907d0
* Run the attached test server * Change "some_existing_host" to your server's IP address, and run the app * The app will connect to the server program, and no error will occurs during the connection (though an error will be rise after 10 seconds before the modification)

Comments

  1. Akira Suzuki 2012-03-01

    The test code might be the following: Titanium.UI.setBackgroundColor('#000'); var app = {}; app.win = Ti.UI.createWindow({ Title: "TCP Socket Test" }); app.textarea = Ti.UI.createTextArea({ value: '', width:'100%', height:'100%', top:0, left:0 }); app.win.add(app.textarea); app.win.open(); var socket; var readBuffer = Ti.createBuffer({ length: 1024 }); var readCallback = function(e) { Ti.API.info("callback called"); if (e.bytesProcessed == -1) { // EOF app.textarea.value += ">> Received socket closed\n"; if (socket.state == Ti.Network.Socket.CONNECTED) socket.close(); return; } app.textarea.value += readBuffer; Ti.Stream.read(socket, readBuffer, readCallback); }; socket = Ti.Network.Socket.createTCP({ host: "192.168.100.101", port: 50000, connected: function(e) { Ti.Stream.read(socket, readBuffer, readCallback); app.textarea.value += ">> Connected to host " + socket.host + "\n"; Ti.API.info("connected"); }, error: function(e) { app.textarea.value += ">> Socket error:" + e.error + "\n"; } }); socket.timeout = 10000; socket.connect();
  2. Michael Pettiford 2012-03-19

    Closing issue Tested with Ti Studio build 2.0.0.201203182248 Ti Mob SDK 2.0.0.v20120319003254 hash r60b6da4c OSX Lion 10.7.3 Nexus S OS 2.3.6 Verified that I received the connected result in ddms and the script printed the correct output

JSON Source