Created
April 29, 2011 19:42
-
-
Save rusticphilosopher/948897 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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