Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-8014] iOS: Ti.Network.Socket.TCP "timeout" property's unit is seconds and not milli-second

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2012-04-19T17:51:57.000+0000
Affected Version/sRelease 1.8.0.1
Fix Version/sRelease 2.0.0, Sprint 2012-06
ComponentsiOS
Labelsmodule_network, qe-testadded
ReporterAkira Suzuki
AssigneeStephen Tramer
Created2012-02-28T03:16:29.000+0000
Updated2012-04-19T17:51:57.000+0000

Description

When the following app run on Android, it outputs ">>Socket error:Unable to connect, IO error" in TextArea after the 10 seconds since the button pressed. On the other hand, on iPhone, it output nothing after 10 seconds. And it output ">>Socket error:Attempt to connect to host timed out" after 10 seconds, by replacing "timeout: 10000" to "timeout: 10". It seems the unit of timeout property in iOS is second, besides the API Doc explicitly describe "in milliseconds".

var win = Ti.UI.createWindow({
	backgroundColor: "#eee",
	layout: "vertical"
});
var textarea = Ti.UI.createTextArea({
	value: "",
	left: 0,
	top: 0,
	width: 320,
	height: 200
});
var button = Ti.UI.createButton({
	title: "Connect",
	top: 20,
	height: 50,
	width: 100
});
win.add(textarea);
win.add(button);

var buffer = Ti.createBuffer();
var socket = Ti.Network.Socket.createTCP({
	host: "192.168.100.200",
	port: 50000,
	timeout: 10000,
	connected: function(e) {
		textarea.value += ">>Connected\n";
		socket.read(buffer);
		textarea.value += buffer + "\n";
	},
	error: function(e) {
		textarea.value += ">>Socket error:" + e.error + "\n";
	}
});

button.addEventListener('click', function(e) {
	socket.connect();
});

win.open();

Comments

  1. Akira Suzuki 2012-02-28

    I assume that the host "192.168.100.200" does NOT exist. If some server is listening on 192.168.100.200:50000, it works as I desire.
  2. Marshall Culpepper 2012-03-15

    Akira's pull request for this issue is here: https://github.com/appcelerator/titanium_mobile/pull/1427
  3. Natalie Huynh 2012-03-19

    Tested on iPhone 3gs 4.3.5 with 2.0.0.v20120319003254
  4. Wilson Luu 2012-04-19

    Reopening to update labels.

JSON Source