{ "id": "65876", "key": "TIMOB-4247", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [ { "id": "11357", "description": "Mobile 1.8.0 M04", "name": "Sprint 2011-25", "archived": true, "released": true, "releaseDate": "2011-06-27" }, { "id": "11331", "description": "", "name": "Release 1.8.0", "archived": true, "released": true, "releaseDate": "2011-10-31" } ], "resolution": { "id": "7", "description": "", "name": "Invalid" }, "resolutiondate": "2011-06-21T09:01:19.000+0000", "created": "2011-05-28T05:59:35.000+0000", "priority": { "name": "Medium", "id": "3" }, "labels": [ "1.7", "ipass1", "module_network" ], "versions": [ { "id": "11244", "name": "Release 1.7.0", "archived": true, "released": true, "releaseDate": "2011-06-13" } ], "issuelinks": [], "assignee": { "name": "stephentramer", "key": "stephentramer", "displayName": "Stephen Tramer", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2017-03-28T21:08:46.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10206", "name": "iOS", "description": "iOS Platform" } ], "description": "Although I can open a socket connection with the new API socket.open(), the thread where I create and open the connection is unable to catch events (Ti.App.addEventListener) fired with (Ti.App.fireEvent).\r\n\r\nSee demonstration below. Edit lines 6 & 7 with host+port of ant socket server (I cannot reveal my client's server).\r\nThe event is neither fired nor catched.\r\nBUT, if you comment line 25 you'll see all is working as usual.\r\n\r\n{code}\r\nvar demo = Ti.UI.createWindow({\r\n}),\r\nsocket = null;\r\n\r\nsocket = Titanium.Network.Socket.createTCP({\r\n\thost: \"server.ip\",\r\n\tport: \"server.socketPort\",\r\n\tconnected: function(e) {\r\n\t\tTi.API.info(\"socket: connected\");\r\n\r\n\t\tvar readBuffer = Ti.createBuffer({length:1024}),\r\n\t\tbytesRead = 0;\r\n\t\twhile((bytesRead = socket.read(readBuffer))>-1) {\r\n\t\t\tvar stringData = Ti.Codec.decodeString({source: readBuffer, length: bytesRead});\r\n\t\t\tTi.API.info(\"socket: received \" + bytesRead + \" bytes:\" + stringData);\r\n\t\t\treadBuffer.clear(); // clear the buffer before the next read\r\n\t\t}\r\n\t\tsocket.close();\r\n\t},\r\n\terror: function(e) {\r\n\t\tTi.API.info(\"socket: error\");\r\n\t\tsocket.close();\r\n\t}\r\n});\r\nsocket.connect(); // comment this, then works as usual\r\n\r\nTi.App.addEventListener('ack', function() {\r\n\tTi.API.info(\"ack catched\");\r\n});\r\n\r\nsetInterval(function() {\r\n\tTi.API.info(\"firing ack\");\r\n\tTi.App.fireEvent('ack');\r\n}, 3000);\r\n\r\n\r\ndemo.open();\r\n{code}\r\n\r\nCode also available at [https://gist.github.com/999073]", "attachment": [], "flagged": false, "summary": "New socket API prevents catching App events once connected", "creator": { "name": "iamyellow", "key": "iamyellow", "displayName": "jordi domenech", "active": true, "timeZone": "Europe/Berlin" }, "subtasks": [], "reporter": { "name": "iamyellow", "key": "iamyellow", "displayName": "jordi domenech", "active": true, "timeZone": "Europe/Berlin" }, "environment": "* Mac OS X 10.6.7\r\n* Titanium Developer 1.2.2\r\n* [DEBUG] Xcode 4.0.2 (it also happens with 4.0.0)\r\n* [DEBUG] Build version 4A2002a\r\n* [INFO] MyApp/1.0 (1.7.0.8be59d3...)", "comment": { "comments": [ { "id": "134448", "author": { "name": "pdowsett", "key": "pdowsett", "displayName": "Paul Dowsett", "active": true, "timeZone": "Europe/London" }, "body": "In order for us to progress this issue, please edit your ticket to include a proper [Use-case|http://wiki.appcelerator.org/display/guides/Contributing+to+Titanium#ContributingtoTitanium-CreatingGoodUsecases].\n\nPlease also use the latest 1.7.X continuous build, and include the version, date and hash here.\n\nKindly read the [Submitting Bug Reports|http://wiki.appcelerator.org/display/guides/Contributing+to+Titanium#ContributingtoTitanium-SubmittingBugReports] guide before raising tickets.\n\nThank you", "updateAuthor": { "name": "pdowsett", "key": "pdowsett", "displayName": "Paul Dowsett", "active": true, "timeZone": "Europe/London" }, "created": "2011-05-30T06:06:01.000+0000", "updated": "2011-05-30T06:06:01.000+0000" }, { "id": "134460", "author": { "name": "iamyellow", "key": "iamyellow", "displayName": "jordi domenech", "active": true, "timeZone": "Europe/Berlin" }, "body": "Hi,\nSorry, I was in a hurry when I wrote the ticket. \n\nSo, I made a very simple app.js with the use case:\nhttps://gist.github.com/999073\n\nEdit lines 6 & 7 with host+port of ant socket server, I could not reveal my client's server.\n\nI realize that the event is neither fired nor catched.\n\nBUT, if you comment line 25 you'll see all is working as usual.\n\nI didn't download the 1.7.X continuous build, my workflow is with github. I forked your repo, fetch and checkout your 1_7_X branch, I mean I have the newest code.\n\nHope this helps, let me know if you anything more, I'm very happy to contribute.", "updateAuthor": { "name": "iamyellow", "key": "iamyellow", "displayName": "jordi domenech", "active": true, "timeZone": "Europe/Berlin" }, "created": "2011-05-30T09:04:41.000+0000", "updated": "2011-05-30T09:04:41.000+0000" }, { "id": "134462", "author": { "name": "pdowsett", "key": "pdowsett", "displayName": "Paul Dowsett", "active": true, "timeZone": "Europe/London" }, "body": "jordi, are you saying that you have compiled the SDK? If so, it won't be possible for us to reproduce the same conditions. Hence, would you test it using one of the packages from our [CI Builds|http://wiki.appcelerator.org/display/guides/Continuous+Builds] site?\n\nNote that when you launch an app, the Titanium version, date and hash will be logged to the console.\n\nOnce you have provided this information, I can move this issue to the relevant project.\n\nThanks in advance\n\n", "updateAuthor": { "name": "pdowsett", "key": "pdowsett", "displayName": "Paul Dowsett", "active": true, "timeZone": "Europe/London" }, "created": "2011-05-30T09:35:46.000+0000", "updated": "2011-05-30T09:36:40.000+0000" }, { "id": "134463", "author": { "name": "pdowsett", "key": "pdowsett", "displayName": "Paul Dowsett", "active": true, "timeZone": "Europe/London" }, "body": "btw, to confirm, you do put quotes around your host and port lines, don't you?", "updateAuthor": { "name": "pdowsett", "key": "pdowsett", "displayName": "Paul Dowsett", "active": true, "timeZone": "Europe/London" }, "created": "2011-05-30T09:37:23.000+0000", "updated": "2011-05-30T09:37:23.000+0000" }, { "id": "134464", "author": { "name": "iamyellow", "key": "iamyellow", "displayName": "jordi domenech", "active": true, "timeZone": "Europe/Berlin" }, "body": "i do :) \nactually, it works, I mean the socket is opened and works like a charm, writes/reads data. The problem is with the events.\n\nYes, I compiled the SDK from source. Anyway, I've downloaded the last CI, made a clean build and the problem persists. The console says:\n[DEBUG] Xcode 4.0.2 (it also happens with 4.0.0)\n[DEBUG] Build version 4A2002a\n[INFO] MyApp/1.0 (1.7.0.8be59d3...)\n\nI cannot see Ti version, date and hash. I'm using Titanium Developer 1.2.2, as Titanium Studio started to crash for a memory problem (and I'm unable to make it work again) a couple of weeks ago.\n\n", "updateAuthor": { "name": "iamyellow", "key": "iamyellow", "displayName": "jordi domenech", "active": true, "timeZone": "Europe/Berlin" }, "created": "2011-05-30T10:02:23.000+0000", "updated": "2011-05-30T10:02:23.000+0000" }, { "id": "134466", "author": { "name": "pdowsett", "key": "pdowsett", "displayName": "Paul Dowsett", "active": true, "timeZone": "Europe/London" }, "body": "Thanks for the info, Jordi - moving this ticket to the correct project.", "updateAuthor": { "name": "pdowsett", "key": "pdowsett", "displayName": "Paul Dowsett", "active": true, "timeZone": "Europe/London" }, "created": "2011-05-30T11:08:27.000+0000", "updated": "2011-05-30T11:08:27.000+0000" }, { "id": "157275", "author": { "name": "stephentramer", "key": "stephentramer", "displayName": "Stephen Tramer", "active": true, "timeZone": "America/Los_Angeles" }, "body": "This is expected behavior. The issue is that once the socket is connected, socket.read() is called - read() is a blocking call on ALL I/O streams by convention. This means until data is received by the socket, ALL activity in the current JS thread is blocked.\n\nThe solution is to use the asynchronous Ti.Stream.read() method. Sockets should, except in very rare cases, use asynchronous read/write. Doing otherwise can result in issues such as windows not closing, events not being fired, stale UI, poor interaction, and other issues.", "updateAuthor": { "name": "stephentramer", "key": "stephentramer", "displayName": "Stephen Tramer", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-06-21T09:01:19.000+0000", "updated": "2011-06-21T09:01:19.000+0000" }, { "id": "416053", "author": { "name": "lmorris", "key": "lmorris", "displayName": "Lee Morris", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Closing ticket as invalid.", "updateAuthor": { "name": "lmorris", "key": "lmorris", "displayName": "Lee Morris", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2017-03-28T21:08:46.000+0000", "updated": "2017-03-28T21:08:46.000+0000" } ], "maxResults": 8, "total": 8, "startAt": 0 } } }