titanium chat server with tcp.socket listening

You must Login before you can answer or comment on any questions.

Hi All

I have been through many many tutorial trying to get tcp.scoket listening to a simple chat server.

Ok i have followed the following tutorial and have a simple chat server running on port 8080 http://nowjs.com/doc/example

All i am trying to do is then embed the code below to listen to connections on that port but i am yet to have any success?

var hostname = '127.0.0.1';
 
    //Create a socket and listen for incoming connections
    var listenSocket = Ti.Network.Socket.createTCP({
        host : hostname,
        port : 8080,
        accepted : function(e) {
            // This where you would usually store the newly-connected socket, e.inbound
            // so it can be used for read / write operations elsewhere in the app.
            // In this case, we simply send a message then close the socket.
            Ti.API.info("Listening socket <" + e.socket + "> accepted incoming connection <" + e.inbound + ">");
            e.inbound.write(Ti.createBuffer({
                value : 'You have been connected to a listening socket.\r\n'
            }));
            e.inbound.close();
            // close the accepted socket
 
        },
        error : function(e) {
            Ti.API.error("Socket <" + e.socket + "> encountered error when listening");
            Ti.API.error(" error code <" + e.errorCode + ">");
            Ti.API.error(" error description <" + e.error + ">");
        }
    });
    // Starts the socket listening for connections, does not accept them
    listenSocket.listen();
    Ti.API.info("Listening now...");
 
    // Tells socket to accept the next inbound connection. listenSocket.accepted gets
    // called when a connection is accepted via accept()
    Ti.API.info("Calling accept.");
    listenSocket.accept({
        timeout : 10000
    });
I am expecting to see the output from the web version in the console of my titanium version.

So if i have my app running in the simulator the web version doesn't work and i need to close the simulator for the web version to start working i have seen the following that is a bit to complex for me to dive straight into i am trying to find a simple example of a chat server with node.js and now.js and working in titanium.

Can someone point me in the right direction thanks

— asked 10 months ago by Ned Turner
2 Comments
  • Since you have looked at a lot of tutorials already, can you tell us what they are so we dont send you information you have already read through?

    — commented 9 months ago by Aaron Saunders

  • https://github.com/nowelium/socket.io-titanium

    http://www.youtube.com/watch?v=10ogNjWCpyc

    http://roguesynaptics.com/post/7076349551/chatsocks-native

    https://github.com/saiten/TiSocketIO

    http://developer.appcelerator.com/blog/2011/05/titanium-mobile-intro-series-sockets.html

    Those are a few any other mainly a simplified step by step would be great thanks, i am awaiting feedback from the develops on most off these.

    https://github.com/nowelium/socket.io-titanium/issues/13

    — commented 9 months ago by Ned Turner

Your Answer

Think you can help? Login to answer this question!