[AC-2236] Android: Close a socket then reopen it, unable to write on it.
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Closed |
Resolution | Cannot Reproduce |
Resolution Date | 2013-12-29T19:35:55.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Studio, Titanium SDK & CLI |
Labels | android |
Reporter | Marvin Rosillette |
Assignee | Shak Hossain |
Created | 2013-11-21T02:32:50.000+0000 |
Updated | 2016-03-08T07:41:14.000+0000 |
Description
Hi everybody and thanks for reading,
I'm going through an issu and I really don't know how to handle it.
First, I create a button to open a new window, instantiate a new socket and connect it to my computer through wifi. Here is the code :
var OptionWindow = require('display/OptionWindow');
var TactSocket = require('trans/tactSocket');
startButton.addEventListener('singletap',function(){
new appDisplay().open({
activityEnterAnimation: Ti.Android.R.anim.fade_in
});
new TactSocket("192.168.1.27",2009).connect();
});
When I close the window open before, I also want to close the socket, so here is the code in the window :
//create a window
var self = Ti.UI.createWindow({
backgroundColor:'#000000',
navBarHidden:true,
fullscreen:true,
windowSoftInputMode : Ti.UI.Android.SOFT_INPUT_ADJUST_RESIZE
});
//Listen to the 'close' event, and fire a new event 'app_close'
self.addEventListener('close',function(){
Ti.App.fireEvent('app_close');
});
Then in my tactsocket function I did this :
function tactSocket(host,port){
var tactsocket = Ti.Network.Socket.createTCP({
host : host,
port : port,
connected : function(e) {
alert('connected socket);
//alert(tactsocket.isWriteable);
},
error : function(e) {
alert('Error (' + e.errorCode + '): ' + e.error);
}
});
//Listen to the 'app_close' event to close the socket
Ti.App.addEventListener('app_close',function(){
tactsocket.close();
alert('socket closed');
});
return self;
}
What happen now :
nothing ?
Hi, Thank your providing the code snippet. Since it is not the complete implementation of the scenario, we can't fully test it. We need runnable test case to provide you necessary feedback. Based on the code you posted, it looks like you are creating objects without assign those to any variable, so we will need to add variables to the test and see if this fails. For example, startButton.addEventListener('singletap',function(){ new appDisplay().open({ activityEnterAnimation: Ti.Android.R.anim.fade_in }); new TactSocket("192.168.1.27",2009).connect(); }); This segment of the code is just creating TackSocket without assigning it to anywhere. If you can provide us more info, we can look into it further. Regards, Mauro
Hello Marvin, I created another testcase (i.e., create a new mobile project and paste this to the app.js):
and looks like it's not failing (the socket will be reused after re initializing it with a .connect(). Can you please take a look and let us know if is working for you as well? For more information on the sockets lifecycle, you can get into this doc: http://docs.appcelerator.com/titanium/3.0/#!/guide/TCP_Socket_API_Spec-section-29004739_TCPSocketAPISpec-Socketlifecycle Best, Mauro
Hi Marvin Rosillette, We are marking this ticket as "cannot reproduce". We posted a sample test case. Please let us know if you continue to get error with our test case. We wait for your feedback. If we don't hear back from you in a week, we will consider this issue resolved and close the ticket.