Hi,
I'm not a little surprised that this work, I have not spent much time on
this but way too many hours with HTTP. It is allowing
me to get back to programming the real application for now.
I also suspect there are many reasons not to do this, but perhaps it will be
interesting to someone anyway, I was surprised it was
even possible.
Upon searching the web I found a little "echo server" based on EventMachine
/ Ruby and looking interesting so I tried my hand
at getting it qoing with my luckless client (with HTTP) and it worked pretty
much straight off.
Here's the qooxdoo side:
*handleRequest : function() {
//URL: http://localhost:4567/hello
M.trace("...>handleRequest()" );
wsUri = "ws://127.0.0.1:4567";
websocket = new WebSocket(wsUri);
websocket.onopen = function(evt) { onOpen(evt) };
websocket.onclose = function(evt) { onClose(evt) };
websocket.onmessage = function(evt) { onMessage(evt) };
websocket.onerror = function(evt) { onError(evt) };
reqHash = "{:DATA=>'catechu'}";
function onOpen(evt) { M.trace("CONNECTED"); doSend(
reqHash ); }
function onClose(evt) { M.trace("DISCONNECTED"); }
function onMessage(evt) { M.trace('RESPONSE: ' + evt.data );
websocket.close(); }
function onError(evt) { M.trace("ERROR: " + evt.data); }
function doSend(message) { M.trace("SENT: " + message);
websocket.send(message); }
M.trace("...<handle_request() " );
}, //END_OF_METHOD( handleRequest );</b>
Here's the very simple but I think performance oriented eventMachine based
WebSocket server:
*require '../lib/em-websocket'
EventMachine::WebSocket.start(:host => "127.0.0.1", :port => 4567, :debug =>
true) do |ws|
ws.onopen { ws.send "Hello Client!"}
ws.onmessage { |msg| ws.send "Message: #{msg}" }
ws.onclose { puts "WebSocket closed" }
ws.onerror { |e| puts "Error: #{e.message}" }
end
*
...and here's the dialog box confirmation of what is happening (client
side):
3560221 test_app0.MO: CONNECTED
3560221 test_app0.MO: SENT: {:DATA=>'catechu'}
3560226 test_app0.MO: RESPONSE: [{:CLASS=>:Acacia_catechu,
:METHOD=>'collection'}, {:HERB_PART=>:HEART_WOOD,
:COLLECTION_WHEN=>:AFTER_FELLING}]
3560227 test_app0.MO: DISCONNECTED
3563997 test_app0.MO: >_bT_ViewerPrevClass()
3563998 test_app0.MO: ...>handleRequest()
3563999 test_app0.MO: ...<handle_request()
<<<<<<<<<<<<<<<<<===
note ASYNCHRONOUS
3564014 test_app0.MO: CONNECTED
3564015 test_app0.MO: SENT: {:DATA=>'catechu'}
3564019 test_app0.MO: RESPONSE: [{:CLASS=>:Acacia_catechu,
:METHOD=>'collection'}, {:HERB_PART=>:HEART_WOOD,
:COLLECTION_WHEN=>:AFTER_FELLING}]
3564020 test_app0.MO: DISCONNECTED
How about that?!
GKoller
--
View this message in context:
http://qooxdoo.678.n2.nabble.com/So-I-have-WebSockets-working-at-very-simple-level-just-thought-I-d-share-tp6903044p6903044.html
Sent from the qooxdoo mailing list archive at Nabble.com.
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2d-oct
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel