tcpsocket not connecting to server
Hi,
I'm using the following code to connect to a TCP server but I don't see any TCP connection being established.
this.socket = Titanium.Network.createTCPSocket({
hostName:this.host,
port:this.port,
mode:Titanium.Network.READ_WRITE_MODE
});
this.socket.addEventListener('read', function(e){
Ti.API.error (e['from'] + ':' + e['data'].text);
});
this.socket.addEventListener('readError', function(e){
this.close();
alert ('read error on websocket');
});
this.socket.addEventListener('writeError', function(e){
this.close();
alert ('read error on websocket');
});
this.socket.connect();
Anyone knows what I might be doing wrong?
Thanks
1 Answer
-
figured out the problem. The connection was actually happening but the data wasn't being sent if I call write immediately after connect. Adding a small delay for write solved the issue.
There should be a callback informing that the connect was successful so that data sending can be started.