Titanium Mobile Intro Series: Sockets

Circuit board and shield icon on blue background with digital code

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 Titanium.Buffer.

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.

Find additional resources on GitHub and in docs.


  1. You mention:


    Are they all the same? And can they all be used in programming code?

  2. Sander,

    “Ti” is just a shortcut for “Titanium” so you are able to use both variants in your source. Titanium.Socket should have been Titanium.Network.Socket. The post has been updated accordingly.

  3. […] cross-platform APIs for TCP/IP networking: Sockets and Streams, and supporting APIs for managing Buffers and […]

  4. hi,

    i want to ask about this part of code above :

    bytesRead = connectSocket.read(readBuffer))

    is TCPSocket has read function?? because i tried to copy and paste that sample code above and it always stop on this part.

    Thanks in advance

Comments are closed.