Skip to content

Instantly share code, notes, and snippets.

@rusticphilosopher
Created April 29, 2011 19:42
Show Gist options
  • Save rusticphilosopher/948897 to your computer and use it in GitHub Desktop.
Save rusticphilosopher/948897 to your computer and use it in GitHub Desktop.
//Create a socket and listen for incoming connections
var listenSocket = Ti.Network.Socket.createTCP({
port: 40404,
accepted: function(e) {
// this where you would usually store the e.inbound value somewhere else so it can be used for
// read / write operations elsewhere in the app
Ti.API.info("Listening socket <" + e.socket + "> accepted incoming connection <" + e.inbound + ">");
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 + ">");
}
});
listenSocket.listen(); // only starts listening for connections, does not accept them
// tells socket to accept the next inbound connection. listenSocket.accepted gets called when a connection is accepted
// via accept()
listenSocket.accept();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment