0

I'm trying to create a socket connection to SockJS server and following the example given here but Titanium keeps on giving me the error "has no method createTCP"

This is the code I'm using

var connectingSocket = Ti.Network.createTCP({
host: host,
port: port,
connected:function(e) {
    e.socket.write(Ti.createBuffer({data: "Well, hello there!"}));
},
error:function(e) {
    Ti.UI.createAlertDialog({
        title:"Socket error: "+e.errorCode,
        message:e.error
    }).show();
    Ti.API.info("CONNECTION has been closed: "+e.socket.host+":"+e.socket.port);
}
});
connectingSocket.connect();
OneScrewLoose
  • 145
  • 1
  • 6
  • 22

2 Answers2

0

I've added Socket to

use Ti.Network.Socket.createTCP instead of Ti.Network.createTCP

OneScrewLoose
  • 145
  • 1
  • 6
  • 22
0

Use Ti.Network.Socket.createTCP instead of Ti.Network.createTCP.

Here is the structure of code, as example.

var clientSocket = Ti.Network.Socket.createTCP({

    host : hostname,
    port : port,
    connected : function(e) {

        e.socket.write(Ti.createBuffer({
            value : 'A message from a connecting socket.'
        }));
    },
    error : function(e) {
        Ti.API.info('Error (' + e.errorCode + '): ' + e.error);
    }
});
 clientSocket.connect();
Jordfräs
  • 8,903
  • 3
  • 27
  • 30
Pranay Kumar
  • 144
  • 5