yankov / webtcp

SockJS/TCP bridge that allows browsers to interact with TCP servers
163 stars 38 forks source link

socket_client.html no longer works due to .on*( vs .on( #3

Closed bantu closed 10 years ago

bantu commented 10 years ago

Example file uses

// On connection callback
socket.on('connect', function(){
  console.log('connected');
})

// This gets called every time new data for this socket is received
socket.on('data', function(data) {
  console.log("received: " + data);
});

socket.on('end', function(data) {
  console.log("socket is closed ");
});

but the socket has

   this.onconnect = function() {
     this.webtcp.sockets[sID].ready = true;
     this.webtcp.sockets[sID].closed = false;
   }

   // some hooks that can be used for additional event handling
   // this will not be overwritten by client event handlers
   this.ondata = function(){}
   this.onend = function(){}
   this.ontimeout = function(){}
   this.ondrain = function(){}

   this.onclose = function() {
     this.webtcp.sockets[sID].ready = false;
     this.webtcp.sockets[sID].closed = true;
   }
bantu commented 10 years ago

The .on function is in WebTCPIO, but the example uses var socket = net.createSocket("127.0.0.1", 1337, options); which returns a Socket object which does not have .on.

bantu commented 10 years ago

Please excuse my stupidity. Socket has the on function from WebTCPIO. My problem was solely that the order of .js includes matters.