Welcome to the third part of our series introducing some of the new features coming up in Titanium Mobile 1.7.0. This second installment focuses on the new
Titanium.Network.Socket module and TCP socket implementation.
Currently, the Titanium Mobile API does not have a cross platform implementation for sockets, and the addition of the
Titanium.Network.Socket module and associated
Titanium.Network.Socket.TCP object will fill that void. Initially, only TCP sockets will be supported but UDP sockets will be added in the future. The addition of support for listening and connecting sockets via TCP will allow application developers to incorporate lower level network logic into their applications. Titanium.Network.Socket.TCP implements the Titanium
Stream interface and therefore relies on the previously mentioned
Socket operations are generally asynchronous and therefore socket callbacks are core to how one operation flows into the next. For example, when connecting to a remote host, you would wait until the
connected callback was invoked and fire off the read / write operations from inside that callback.
Once a socket is connected, IO operations leave the scope of Ti.Network.Socket and move into the realm of general Stream IO. Again, because sockets are naturally asynchronous, IO interactions with them should generally be conducted through the
Ti.Stream module. Lastly, while sockets can be an extremely powerful part of your developer tool box, network programming is non-trivial and investigation into the basics of how BSD sockets work is suggested.