Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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

— asked June 12th 2010 by Gaurav Srivastva
  • connection
  • failed
  • iphone
  • tcpsocket
0 Comments

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.

    — answered June 12th 2010 by Gaurav Srivastva
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.