how to use or integrate socket in qooxdoo

classic Classic list List threaded Threaded
19 messages Options
Reply | Threaded
Open this post in threaded view
|

how to use or integrate socket in qooxdoo

matteomasina
Hi, I'm just developing an application, that uses communication with php backend to get some system informations.
Everything working well, but to get the Qooxdoo fronted update, I'm using a timer sending request to the php backend any tot seconds;
I would like to improve this so I had the idea to use the socket, and to fire an update event on qooxdoo frontend, so that application will be updated only when there is something new to show.

Have you got any idea where to start to deploy this ? I have read a lot of post where the arguements are similar, but I haven't find nothing from where to start, or any example to view.

Can you help me or send some feedback if anyone has already tried this solution ?

Regards Matteo Masina
Reply | Threaded
Open this post in threaded view
|

Re: how to use or integrate socket in qooxdoo

Thomas Herchenroeder

On 09/03/2013 03:08 PM, matteomasina wrote:

> Hi, I'm just developing an application, that uses communication with php
> backend to get some system informations.
> Everything working well, but to get the Qooxdoo fronted update, I'm using a
> timer sending request to the php backend any tot seconds;
> I would like to improve this so I had the idea to use the socket, and to
> fire an update event on qooxdoo frontend, so that application will be
> updated only when there is something new to show.
>
> Have you got any idea where to start to deploy this ? I have read a lot of
> post where the arguements are similar, but I haven't find nothing from where
> to start, or any example to view.
>
> Can you help me or send some feedback if anyone has already tried this
> solution ?

There was one user using qooxdoo together with web sockets [1], but he
didn't disclose much of how he did it. But it should be straight
forward, just use the HTML5 socket API in e.g. a method of one of your
application classes. Examples for web sockets abound, e.g. [2][3].


T.

[1]
http://qooxdoo.678.n2.nabble.com/html5-question-about-websocket-usage-td5569725.html
[2] http://www.websocket.org/demos.html
[3] http://html5demos.com/web-socket#view-source



------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: how to use or integrate socket in qooxdoo

benco
In reply to this post by matteomasina
Hi,

It's not that difficult actually.

If your application must be cross-browser compatible (w/ IE6+ for instance), this package will be useful for your qooxdoo app: https://github.com/gimite/web-socket-js (flash fallback). There are other different implementations (based on ActiveX htmlfile etc...) but considering Flash is very common, I'm OK with it.

In the example, you can see there is the following code.
<pre>
ws.onmessage = function(e) {
    // Receives a message.
    alert(e.data);
  };
</pre>

In this function, you can manage how to update your qooxdoo widgets.

For the server, there are tons of projects available on github too, like this one for instance: https://github.com/nicokaiser/php-websocket

Requirements are in general:
* CLI and set_time_limit access
* php_sockets support
* at least a special communication port open between the server and the client (antivirus and firewall softwares may alter or block the process).

What you need to remember is that there was a lot of "draft releases" of the websocket protocol (so different versions of the "language"). It implies that your php server script and your browser must speak the same language too. So, the best is to force the browser to use the flash version rather than the native one depending on the websocket version supported.

Also I recommend only passing "small messages" between clients and not big json datasets for instance.
For instance, Someone update the client ID=6783 in a CRM application. A message is then generated {model:"clients", action:"update", targetId:6783, data:{address:"Qooxdoo Street, 45"}} and sent to the websocket server. The server then propagates the infos to the other clients and you can update the client's page.

Voilà, I hope it helps a bit. Feel free to ask questions if necessary.

Best Regards,

Benoît.
Reply | Threaded
Open this post in threaded view
|

Re: how to use or integrate socket in qooxdoo

matteomasina
Hi guys thank you a lot for your answers, today I'm gonna check for your solutions and I'll tell you the results.
In these days I found also this :

http://simplapi.wordpress.com/2012/07/02/linking-socket-io-to-qooxdoo/

do you think that could be usefull ?

Regards Matteo Masina
Reply | Threaded
Open this post in threaded view
|

Re: how to use or integrate socket in qooxdoo

benco
Hi,

matteomasina wrote
Sounds a good alternative as it wraps the library in a qooxdoo class.
But on the server side, be sure to use a PHP solution as the socket.io server is nodejs-based if I remember correctly. Check also if it use the same version of the protocol.

Best,

Benoît.
Reply | Threaded
Open this post in threaded view
|

Re: how to use or integrate socket in qooxdoo

Andreas Parusel
In reply to this post by Thomas Herchenroeder
Hi,

Socket.io would definetly get your job done but it might be overblown as it requires components on the client as well as on the server-side. I suggest to take a step back and have a look at the general requirements of your application:

- Is a bidirectional realtime-channel required or Is the communication mostly unidirectional from server to client?
- what kind of data will be sent? A binary stream or are simple text-messages (e.g. notifcations) good enough?

If both questions can be answered with 'yes' I would rather have look at Server-sent events. They are basically just a special form of HTTP-message and can be therefore implemented with every simple http-server without any additional modules. A further reading on Server-sent events with a short tutorial and also links to polyfils for older browsers (no flash required) can be found here:

http://html5doctor.com/server-sent-events/

Best regards
Andreas  
 
Am 03.09.2013 um 17:10 schrieb thron7 <[hidden email]>:

>
> On 09/03/2013 03:08 PM, matteomasina wrote:
>> Hi, I'm just developing an application, that uses communication with php
>> backend to get some system informations.
>> Everything working well, but to get the Qooxdoo fronted update, I'm using a
>> timer sending request to the php backend any tot seconds;
>> I would like to improve this so I had the idea to use the socket, and to
>> fire an update event on qooxdoo frontend, so that application will be
>> updated only when there is something new to show.
>>
>> Have you got any idea where to start to deploy this ? I have read a lot of
>> post where the arguements are similar, but I haven't find nothing from where
>> to start, or any example to view.
>>
>> Can you help me or send some feedback if anyone has already tried this
>> solution ?
>
> There was one user using qooxdoo together with web sockets [1], but he
> didn't disclose much of how he did it. But it should be straight
> forward, just use the HTML5 socket API in e.g. a method of one of your
> application classes. Examples for web sockets abound, e.g. [2][3].
>
>
> T.
>
> [1]
> http://qooxdoo.678.n2.nabble.com/html5-question-about-websocket-usage-td5569725.html
> [2] http://www.websocket.org/demos.html
> [3] http://html5demos.com/web-socket#view-source
>
>
>
> ------------------------------------------------------------------------------
> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
> Discover the easy way to master current and previous Microsoft technologies
> and advance your career. Get an incredible 1,500+ hours of step-by-step
> tutorial videos with LearnDevNow. Subscribe today and save!
> http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
> _______________________________________________
> qooxdoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel


------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: how to use or integrate socket in qooxdoo

benco
Andreas Parusel wrote
Hi,If both questions can be answered with 'yes' I would rather have look at Server-sent events.
Good point Andreas. I personally never though about Server-sent events (in my case, the client must sent messages in realtime, so websocket usage was mandatory) but it's really interesting :) !
Reply | Threaded
Open this post in threaded view
|

Re: how to use or integrate socket in qooxdoo

Thomas Herchenroeder

On 09/04/2013 11:54 AM, benco wrote:
> Andreas Parusel wrote
>> Hi,If both questions can be answered with 'yes' I would rather have look
>> at Server-sent events.
> Good point Andreas. I personally never though about Server-sent events (in
> my case, the client must sent messages in realtime, so websocket usage was
> mandatory) but it's really interesting :) !

Which layer are SSE using on the client side, if not websockets?!


T.


------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: how to use or integrate socket in qooxdoo

matteomasina
In reply to this post by matteomasina
The software I'm developing has these needed :

- cross platform
- the possibility of transfer not only text data, but binary data too.

so after a while of studying I beleive that the integration of HTML5 websocket should be good !

But in which way I can integrate HTML5 websocket in qooxdoo Desktop App ?

Thank you
Reply | Threaded
Open this post in threaded view
|

Re: how to use or integrate socket in qooxdoo

Andreas Parusel
For the integration, I see basically two choices.

1. you simply create a new WebSocket-Object early in your application-lifecycle and use the native WS-events in your code. Native events and qooxdoo-events can exist side-by-side.

2. You use/write a wrapper for making the web socket a better fit to the qooxdoo world. You posted an example of such a wrapper yourself earlier in this discussion.

Best,
Andreas


Am 04.09.2013 um 14:07 schrieb matteomasina <[hidden email]>:

> The software I'm developing has these needed :
>
> - cross platform
> - the possibility of transfer not only text data, but binary data too.
>
> so after a while of studying I beleive that the integration of HTML5
> websocket should be good !
>
> But in which way I can integrate HTML5 websocket in qooxdoo Desktop App ?
>
> Thank you
>
>
>
> --
> View this message in context: http://qooxdoo.678.n2.nabble.com/how-to-use-or-integrate-socket-in-qooxdoo-tp7584526p7584543.html
> Sent from the qooxdoo mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
> Discover the easy way to master current and previous Microsoft technologies
> and advance your career. Get an incredible 1,500+ hours of step-by-step
> tutorial videos with LearnDevNow. Subscribe today and save!
> http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
> _______________________________________________
> qooxdoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel


------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: how to use or integrate socket in qooxdoo

matteomasina
Hi Andreas,

I've posted a sample but for using SimpleIO.js that uses node.js, but I have already my server code working, developed in c#. So that my problem is understand hot to integrate in qooxdoo something similar to this :


     var ws = new WebSocket("ws://localhost:3500/test");
     ws.onopen = function()
     {
                alert("Connection open");
        // Web Socket is connected, send data using send()
        ws.send("INVIO MESSAGGIO");
        alert("Message is sent...");
     };
     ws.onmessage = function (evt)
     {
        var received_msg = evt.data;
        alert("Message is received...");
     };
     ws.onclose = function()
     {
        // websocket is closed.
        alert("Connection is closed...");
     };

 

My server work perfectly with HTML5 ask and answer but how to insert this in my Qooxdoo Desktop Application ?

Thank you to all for your help

Matteo
Reply | Threaded
Open this post in threaded view
|

Re: how to use or integrate socket in qooxdoo

Andreas Parusel
Hi Matteo,

In whatever class it makes the most sense in your app, assign a new WebSocket-Instance to a member in the constructor. Here a small example, I just tested it myself (works :) ). It illustrate you a possible way to go. 

/**
 * @ignore(WebSocket)
 */
qx.Class.define("test.SomeClass",
{
  extend : qx.core.Object,

  construct : function() 
  {
  this.base(arguments);

  this.socket = new WebSocket('ws://localhost:8000/events');

  // native event-listener
  this.socket.addEventListener("message", this.onSocketMessage , false)
  },

  members :
  {
  socket : null,

  onSocketMessage : function(e) {
  console.log(e.data)
  }
  }
});

Best,
Andreas
________________________________________
Von: matteomasina [[hidden email]]
Gesendet: Samstag, 7. September 2013 12:52
An: [hidden email]
Betreff: Re: [qooxdoo-devel] how to use or integrate socket in qooxdoo

Hi Andreas,

I've posted a sample but for using SimpleIO.js that uses node.js, but I have
already my server code working, developed in c#. So that my problem is
understand hot to integrate in qooxdoo something similar to this :


 /    var ws = new WebSocket("ws://localhost:3500/test");
     ws.onopen = function()
     {
                alert("Connection open");
        // Web Socket is connected, send data using send()
        ws.send("INVIO MESSAGGIO");
        alert("Message is sent...");
     };
     ws.onmessage = function (evt)
     {
        var received_msg = evt.data;
        alert("Message is received...");
     };
     ws.onclose = function()
     {
        // websocket is closed.
        alert("Connection is closed...");
     };/


My server work perfectly with HTML5 ask and answer but how to insert this in
my Qooxdoo Desktop Application ?

Thank you to all for your help

Matteo



--
View this message in context: http://qooxdoo.678.n2.nabble.com/how-to-use-or-integrate-socket-in-qooxdoo-tp7584526p7584568.html
Sent from the qooxdoo mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: how to use or integrate socket in qooxdoo

matteomasina
Andreas thank you a lot for your help I think I'm really near to the solution.

I've tried you code for test, but sorry not works.

I'm not so expert in extend object so my questions are :

- extending the websocket in the way you show me, how can I use the websocket method to estabilish the connection , send data and close connection ?

 ws.onopen = function()
     {
                alert("Connection open");
        // Web Socket is connected, send data using send()
        ws.send("INVIO MESSAGGIO");
        alert("Message is sent...");
     };
     ws.onmessage = function (evt)
     {
        var received_msg = evt.data;
        alert();
        alert("Message is received..." + received_msg);
     };
     ws.onclose = function()
     {
        // websocket is closed.
        alert("Connection is closed...");
     };


sorry to disturb you again, but I need this help to continue the work. Or send me some link where I can understand how to extend object in qooxdoo.

Regards Matteo
Reply | Threaded
Open this post in threaded view
|

Re: how to use or integrate socket in qooxdoo

Andreas Parusel
Hi Matteo,

does your sample-code work? Is everything okay with your WebSocket-server? What kind of server with which WebSocket-Implementation are you using?

To make sure that we are talking about the same thing, I changed my code so test the WebSocket against a publicly WebSocket test-server ("http://www.websocket.org/echo.html").

Here is the code:

> /**
>  * @ignore(WebSocket)
>  */
> qx.Class.define("testwebsocket.WebSocket",
> {
>   extend : qx.core.Object,
>
>   construct : function()
>   {
>     this.base(arguments);
>
>     this.socket = new WebSocket('ws://echo.websocket.org/');
>
>     // register native event-listeners
>     this.socket.addEventListener("open", this.onSocketOpen , false);
>     this.socket.addEventListener("message", this.onSocketMessage , false);
>     this.socket.addEventListener("close", this.onSocketClose , false);
>     this.socket.addEventListener("error", this.onSocketError , false);
>   },
>
>   members :
>   {
>     // holding the native WebSocket
>     socket : null,
>
>     // event-handlers
>     onSocketOpen : function(e) {
>       console.log("Connection opened");
>     },
>
>     onSocketMessage : function(e) {
>       console.log("Message received: " + e.data);
>     },
>
>     onSocketClose : function(e) {
>       console.log("Connection closed");
>     },
>
>     onSocketError : function(e) {
>       console.log("An error occured!");
>     },
>
>     send : function(message)
>     {
>       this.socket.send(message);
>     }
>   }
> });

To test it, create an instance of this class and assign it to a global variable:

> ws = new testwebsocket.WebSocket();

Now start you application and open the developer-console of your browser. You should already see the log "Connection opened"). Then send a message to the server, just type ws.send("You message text") into the browser-console and the server will immediately echo it.

Best,
Andreas


Am 08.09.2013 um 11:30 schrieb matteomasina <[hidden email]>:

> Andreas thank you a lot for your help I think I'm really near to the
> solution.
>
> I've tried you code for test, but sorry not works.
>
> I'm not so expert in extend object so my questions are :
>
> - extending the websocket in the way you show me, how can I use the
> websocket method to estabilish the connection , send data and close
> connection ?
>
> /ws.onopen = function()
>     {
> alert("Connection open");
>        // Web Socket is connected, send data using send()
>        ws.send("INVIO MESSAGGIO");
>        alert("Message is sent...");
>     };
>     ws.onmessage = function (evt)
>     {
>        var received_msg = evt.data;
>        alert();
>        alert("Message is received..." + received_msg);
>     };
>     ws.onclose = function()
>     {
>        // websocket is closed.
>        alert("Connection is closed...");
>     };/
>
> sorry to disturb you again, but I need this help to continue the work. Or
> send me some link where I can understand how to extend object in qooxdoo.
>
> Regards Matteo
>
>
>
> --
> View this message in context: http://qooxdoo.678.n2.nabble.com/how-to-use-or-integrate-socket-in-qooxdoo-tp7584526p7584570.html
> Sent from the qooxdoo mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
> Discover the easy way to master current and previous Microsoft technologies
> and advance your career. Get an incredible 1,500+ hours of step-by-step
> tutorial videos with LearnDevNow. Subscribe today and save!
> http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk
> _______________________________________________
> qooxdoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel


------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: how to use or integrate socket in qooxdoo

matteomasina
Hi Andreas thank you a lot,

I've created a qooxdoo Window and when on window open event I've created the websocket.

Everything is working well.
the websocket connects to my server and send the message too !!! Great !

the only problem it's about fire event on messege received.

I tried  :

ws.addListener("message", function(e) {
                        alert("ricevuto messaggio");
                        }, this);

and on connection open

ws.addListener("open", function(e) {
                        alert("ricevuto messaggio");
                        }, this);

but seems not fire event !
any idea ?

thanks for everything, in few days I'll post my code so that if someone wnat to reuse this id ready !!!

Regards Matteo
Reply | Threaded
Open this post in threaded view
|

Re: how to use or integrate socket in qooxdoo

Andreas Parusel
Hi Matteo,

You have to replace "this" with "false" in your code, then it should work. Notice that the WebSocket is a native Object and not a qooxdoo-Object, so you have to use the native addListener()-method, which has different parameters than its qooxdoo counterpart:

https://developer.mozilla.org/en-US/docs/Web/API/EventTarget.addEventListener:

Best,Andreas
Am 09.09.2013 um 12:51 schrieb matteomasina <[hidden email]>:

> Hi Andreas thank you a lot,
>
> I've created a qooxdoo Window and when on window open event I've created the
> websocket.
>
> Everything is working well.
> the websocket connects to my server and send the message too !!! Great !
> ve
> the only problem it's about fire event on messege received.
>
> I tried  :
>
> ws.addListener("message", function(e) {
>        alert("ricevuto messaggio");
> }, this);
>
> and on connection open
>
> ws.addListener("open", function(e) {
>        alert("ricevuto messaggio");
> }, this);
>
> but seems not fire event !
> any idea ?
>
> thanks for everything, in few days I'll post my code so that if someone wnat
> to reuse this id ready !!!
>
> Regards Matteo
>
>
>
> --
> View this message in context: http://qooxdoo.678.n2.nabble.com/how-to-use-or-integrate-socket-in-qooxdoo-tp7584526p7584579.html
> Sent from the qooxdoo mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
> Discover the easy way to master current and previous Microsoft technologies
> and advance your career. Get an incredible 1,500+ hours of step-by-step
> tutorial videos with LearnDevNow. Subscribe today and save!
> http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk
> _______________________________________________
> qooxdoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel


------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: how to use or integrate socket in qooxdoo

matteomasina
Thanks I'm watching for native objects, I hope to find the way, changing this to false in my script doesnt works.

Regards  Matteo
Reply | Threaded
Open this post in threaded view
|

Re: how to use or integrate socket in qooxdoo

matteomasina
Where I'm wrong ? I try to intercept the Event from Native object, but this don't fire on message arrives.

var ws = new test.WebSocket();

qx.bom.Event.addNativeListener(ws,"message", function(e) {
                        alert("connessione aperta");
                        }, false);


/**
  * @ignore(WebSocket)
  */
 qx.Class.define("test.WebSocket",
 {
   extend : qx.core.Object,

   construct : function()
   {
     this.base(arguments);

     this.socket = new WebSocket('ws://127.0.0.1:3500/');

     // register native event-listeners
     this.socket.addEventListener("open", this.onSocketOpen , false);
     this.socket.addEventListener("message", this.onSocketMessage , false);
     this.socket.addEventListener("close", this.onSocketClose , false);
     this.socket.addEventListener("error", this.onSocketError , false);
   },
   
  events :
  {
    "reload" : "qx.event.type.Event",
    "post"   : "qx.event.type.Data"
  },
   
   
   members :
   {
     // holding the native WebSocket
     socket : null,

     // event-handlers
     onSocketOpen : function(e) {
       console.log("Connection opened");      
     },

     onSocketMessage : function(e) {
       console.log("Message received: " + e.data);
       alert(e.data);
     },

     onSocketClose : function(e) {
       console.log("Connection closed");
     },

     onSocketError : function(e) {
       console.log("An error occured!");
     },

     send : function(message)
     {
       this.socket.send(message);
     }
   }
 });


Reply | Threaded
Open this post in threaded view
|

Re: how to use or integrate socket in qooxdoo

Andreas Parusel
This cannot work. Take a look at the API of addNativeListener:
http://demo.qooxdoo.org/current/apiviewer/#qx.bom.Event~addNativeListener!method_public

The first argument passed has to be "any valid native event target". You are passing a qooxdoo-object. If something could maybe work, then passing ws.socket...

Anyway, I don't understand the purpose of what you are trying to do. I see no need for intercepting the events. You have the handlers in the code below, do whatever is needed within them.

If you are trying to fire qooxdoo events, have a closer look at the link you posted earlier:

http://simplapi.wordpress.com/2012/07/02/linking-socket-io-to-qooxdoo/

Like in lines 116 - 125 you could fire own events within each event-handler.


A little advice in the end: 
Don't use alert(), use console.log() instead. Alert() stops any further JavaScript-execution which can be confusion sometimes.

Cheers,
Andreas

________________________________________
Von: matteomasina [[hidden email]]
Gesendet: Montag, 9. September 2013 17:24
An: [hidden email]
Betreff: Re: [qooxdoo-devel] how to use or integrate socket in qooxdoo

Where I'm wrong ? I try to intercept the Event from Native object, but this
don't fire on message arrives.

var ws = new test.WebSocket();

qx.bom.Event.addNativeListener(ws,"message", function(e) {
                        alert("connessione aperta");
                        }, false);


/**
  * @ignore(WebSocket)
  */
 qx.Class.define("test.WebSocket",
 {
   extend : qx.core.Object,

   construct : function()
   {
     this.base(arguments);

     this.socket = new WebSocket('ws://127.0.0.1:3500/');

     // register native event-listeners
     this.socket.addEventListener("open", this.onSocketOpen , false);
     this.socket.addEventListener("message", this.onSocketMessage , false);
     this.socket.addEventListener("close", this.onSocketClose , false);
     this.socket.addEventListener("error", this.onSocketError , false);
   },

  events :
  {
    "reload" : "qx.event.type.Event",
    "post"   : "qx.event.type.Data"
  },


   members :
   {
     // holding the native WebSocket
     socket : null,

     // event-handlers
     onSocketOpen : function(e) {
       console.log("Connection opened");
     },

     onSocketMessage : function(e) {
       console.log("Message received: " + e.data);
       alert(e.data);
     },

     onSocketClose : function(e) {
       console.log("Connection closed");
     },

     onSocketError : function(e) {
       console.log("An error occured!");
     },

     send : function(message)
     {
       this.socket.send(message);
     }
   }
 });






--
View this message in context: http://qooxdoo.678.n2.nabble.com/how-to-use-or-integrate-socket-in-qooxdoo-tp7584526p7584588.html
Sent from the qooxdoo mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel