WebSockets support?

596 views
Skip to first unread message

Merco

unread,
Sep 23, 2011, 10:01:17 AM9/23/11
to mozilla-rhino
Hello @ all.

I want to use Rhino to embedd an JavaScript which is using a WebSocket
Connection into my Java application.

Is this possible with Rhino, if yes with which version?

Thanks for your help!

felipe valdez

unread,
Sep 23, 2011, 10:45:24 AM9/23/11
to mozill...@googlegroups.com
http://jwebsocket.org/
--
312-444-2124
Skype: f3l.headhunter
Casa: 8043901



Merco

unread,
Sep 26, 2011, 6:37:59 AM9/26/11
to mozilla-rhino
Thank you for your fast post!

But i don't want to use a webSocket-Connection from Java. I have a
extern JavaScript which is using an webSocket-Connection which should
not be changed. This script schould be automated readed by my Java App
and executed over Rhino.

Does anyone know if Rhino is supporting this?

On 23 Sep., 16:45, felipe valdez <felipeval...@gmail.com> wrote:
> http://jwebsocket.org/
>

felipe valdez

unread,
Sep 26, 2011, 10:35:00 AM9/26/11
to mozill...@googlegroups.com
any java api can be used from rhino
so you can make a layer, that lets you not change the code:

old code:

function a()
function b()


java code:

function a(){call jsfunction_a() websocket_from_java_and_behave_like old_a()}
functino b(){call jsfunction_b()  websocket_from_java_and_behave_like old_b()}


java layer:

jsfunction_a(){
call java api
}

lots of unit tests..

Merco

unread,
Sep 27, 2011, 2:55:01 AM9/27/11
to mozilla-rhino
i don't want to use an java api vom javascript.

The problem is in my JavaScript Code is an call of the new webSockets
which where new in HTML5.

JavaScript code example:
testOpenSocket();



function testOpenSocket(){



socket = new WebSocket("ws://192.168.124.125:123");

//Associate listeners

socket.onopen = function(evt) {

returnValue = "Conneciton established!";

};

}

If executed with Rhino it creates this error message:

javax.script.ScriptException:
sun.org.mozilla.javascript.internal.EcmaError: ReferenceError:
"WebSocket" is not defined. (<Unknown source>#5) in <Unknown source>
at line number 5

at com.sun.script.javascript.RhinoScriptEngine.eval(Unknown Source)

at com.sun.script.javascript.RhinoScriptEngine.eval(Unknown Source)

at javax.script.AbstractScriptEngine.eval(Unknown Source)

at
javaScriptIntegration.JavaScriptIntegration.test(JavaScriptIntegration.java:
53)

at javaScriptIntegration.startTest2.main(startTest2.java:7)

Caused by: sun.org.mozilla.javascript.internal.EcmaError:
ReferenceError: "WebSocket" is not defined. (<Unknown source>#5)

at
sun.org.mozilla.javascript.internal.ScriptRuntime.constructError(Unknown
Source)

at
sun.org.mozilla.javascript.internal.ScriptRuntime.constructError(Unknown
Source)

at
sun.org.mozilla.javascript.internal.ScriptRuntime.notFoundError(Unknown
Source)

at
sun.org.mozilla.javascript.internal.ScriptRuntime.nameOrFunction(Unknown
Source)

at sun.org.mozilla.javascript.internal.ScriptRuntime.name(Unknown
Source)

at
sun.org.mozilla.javascript.internal.Interpreter.interpretLoop(Unknown
Source)

at sun.org.mozilla.javascript.internal.Interpreter.interpret(Unknown
Source)

at
sun.org.mozilla.javascript.internal.InterpretedFunction.call(Unknown
Source)

at
sun.org.mozilla.javascript.internal.ContextFactory.doTopCall(Unknown
Source)

at
sun.org.mozilla.javascript.internal.ScriptRuntime.doTopCall(Unknown
Source)

at
sun.org.mozilla.javascript.internal.InterpretedFunction.exec(Unknown
Source)

at sun.org.mozilla.javascript.internal.Context.evaluateReader(Unknown
Source)

... 5 more

On 26 Sep., 16:35, felipe valdez <felipeval...@gmail.com> wrote:
> any java api can be used from rhino
> so you can make a layer, that lets you not change the code:
>
> old code:
>
> function a()
> function b()
>
> java code:
>
> function a(){call jsfunction_a() websocket_from_java_and_behave_like
> old_a()}
> functino b(){call jsfunction_b()  websocket_from_java_and_behave_like
> old_b()}
>
> java layer:
>
> jsfunction_a(){
> call java api
>
> }
>
> lots of unit tests..
>

Tony Zakula

unread,
Sep 27, 2011, 9:35:17 AM9/27/11
to mozill...@googlegroups.com
Yes, you answered your own question. That is HTML5 not JavaScript.
Browsers implement HTML specs, not JavaScript engines.

Tony Z

Andy Grohe

unread,
Sep 27, 2011, 9:44:46 AM9/27/11
to mozill...@googlegroups.com
If you are looking to write JavaScript on the server and have an HTML parser, you have to look at node.js.

Sent from my iPhone

Tony Zakula

unread,
Sep 27, 2011, 9:49:34 AM9/27/11
to mozill...@googlegroups.com
That is not quite correct. There are many Java HTML parsers out there
that will plug right in. The Eco-system for Java is massive compared
to node.

Tony Z

felipe valdez

unread,
Sep 27, 2011, 10:55:37 AM9/27/11
to mozill...@googlegroups.com
you'd be creating a layer, so it looks the same and the code doesn't change.


this conversation feels like this:


1> I need to be healthy
2> then eat fruits and vegetables
1> I don't want to
2> ...




On Tue, Sep 27, 2011 at 1:55 AM, Merco <Christop...@hs-augsburg.de> wrote:

RickB

unread,
Dec 16, 2011, 7:02:58 AM12/16/11
to mozill...@googlegroups.com
The easiest solution would be to wrap a Java web socket library to create a "WebSocket" class with the same interface as the HTML5 specification.  Should be quite do-able, but I don't know of anyone who has done it already.

felipe valdez

unread,
Dec 16, 2011, 5:54:20 PM12/16/11
to mozill...@googlegroups.com
I love that idea!
it would be a way to port a bunch of stuff, along with gwt, no?


On Fri, Dec 16, 2011 at 7:02 AM, RickB <rbul...@gmail.com> wrote:
The easiest solution would be to wrap a Java web socket library to create a "WebSocket" class with the same interface as the HTML5 specification.  Should be quite do-able, but I don't know of anyone who has done it already.



Reply all
Reply to author
Forward
0 new messages