GF 3.1.1 WebSocket support - cannot enable WebSockets

GF 3.1.1 WebSocket support - cannot enable WebSockets

17 replies [ Last post]
hsch
Offline
Joined: 2012-01-17
Points: 0

Hi,
i want to develop an websocket application. I already developed an websocket client using weberknecht-websockets and tested it with an server implementation using jetty webserver and it works great!
Now i want to try out glassfish. I read that glassfish 3.1.1 supports websockets. So i googled a lot and found a few tutorials which describes how to implement the server side for websockets for glassfish.
My Server Side Implementation looks like:
WebSocketServlet:

package de.gfwebsocket;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sun.grizzly.websockets.WebSocketEngine;

/**
* Servlet implementation class WebSocketServlet
*/
public class WebSocketServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

public WebSocketServlet() {
super();
// TODO Auto-generated constructor stub
}

public void init(ServletConfig config) throws ServletException {
// TODO Auto-generated method stub
WebSocketEngine.getEngine().register(new WebSocketConnection());
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
PrintWriter writer = response.getWriter();
writer.println("<html>");
writer.println("<head><title>Hello World Servlet</title></head>");
writer.println("<body>");
writer.println("<h1>Es ist der " + format.format(new Date()) + " Uhr</h1>");
writer.println("<body>");
writer.println("</html>");
writer.flush();
writer.close();
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}

WebSocketConnection
package de.gfwebsocket;

import com.sun.grizzly.tcp.Request;
import com.sun.grizzly.websockets.WebSocket;
import com.sun.grizzly.websockets.WebSocketApplication;
import com.sun.grizzly.websockets.WebSocketListener;

public class WebSocketConnection extends WebSocketApplication{

@Override
public WebSocket createSocket(WebSocketListener... listeners) {
// TODO Auto-generated method stub
return new WebSocketDataProcess(listeners);
}

@Override
public void onClose(WebSocket socket) {
// TODO Auto-generated method stub
super.onClose(socket);
}

@Override
public void onConnect(WebSocket socket) {
// TODO Auto-generated method stub
super.onConnect(socket);
}

@Override
public void onMessage(WebSocket socket, String text) {
socket.send(text);
//super.onMessage(socket, text);
}

// return true if you want to communicate over websocket otherwise return false
@Override
public boolean isApplicationRequest(Request arg0) {
// TODO Auto-generated method stub
return true;
}
}
WebSocketDataProcess

package de.gfwebsocket;

import com.sun.grizzly.websockets.BaseServerWebSocket;
import com.sun.grizzly.websockets.WebSocketListener;

public class WebSocketDataProcess extends BaseServerWebSocket{

public WebSocketDataProcess(WebSocketListener... listeners) {
// TODO Auto-generated constructor stub
super(listeners);
}

}
I exported this project as an .war-File and deployed it in GlassFish via web console. I tried to reach it by using firefox and it showed me the actual time as expected.
But if i try my client to connect with the websocket server, it failed. I get an exception on client side: "connection failed: unknown status code 200". My Client works with WebSocket. As i said, i tested it with a jetty websocket server implementation.
So i tried to enable websockets in glassfish 3.1.1. I started the server with "./asadmin start-server" and then i tried "./asadmin set configs.config.server-config.network-config.protocols.protocol.http-listener-1.http.websockets-support-enabled=true". the command works, but i get the error code again. :(

So, can anybody help me?
Thank you for your help in advance.
Best regards
hsch
** I don't know how to wrap my code in java-tags.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
oleksiys
Offline
Joined: 2006-01-25
Points: 0

Hi,

what exactly you see in the console, when you try to enable websockets using
./asadmin start-server" and then i tried "./asadmin set
configs.config.server-config.network-config.protocols.protocol.http-listener-1.http.websockets-support-enabled=true

?

Thanks.

WBR,
Alexey.

On 01/17/2012 03:35 PM, forums@java.net wrote:
> Hi,
>
> i want to develop an websocket application. I already developed an
> websocket
> client using weberknecht-websockets and tested it with an server
> implementation using jetty webserver and it works great!
>
> Now i want to try out glassfish. I read that glassfish 3.1.1 supports
> websockets. So i googled a lot and found a few tutorials which
> describes how
> to implement the server side for websockets for glassfish.
>
> My Server Side Implementation looks like:
>
> *WebSocketServlet:*
>
> [java]
>
> package de.gfwebsocket;
> import java.io.IOException;
> import java.io.PrintWriter;
> import java.text.SimpleDateFormat;
> import java.util.Date;
> import javax.servlet.ServletConfig;
> import javax.servlet.ServletException;
> import javax.servlet.http.HttpServlet;
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
> import com.sun.grizzly.websockets.WebSocketEngine;
> /**
> * Servlet implementation class WebSocketServlet
> */
> public class WebSocketServlet extends HttpServlet {
> private static final long serialVersionUID = 1L;
>
> public WebSocketServlet() {
> super();
> // TODO Auto-generated constructor stub
> }
>
> public void init(ServletConfig config) throws ServletException {
> // TODO Auto-generated method stub
> WebSocketEngine.getEngine().register(new
> WebSocketConnection());
> }
>
> protected void doGet(HttpServletRequest request, HttpServletResponse
> response) throws ServletException, IOException {
> SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy
> HH:mm:ss");
> PrintWriter writer = response.getWriter();
> writer.println("");
> writer.println("Hello World
> Servlet");
> writer.println("");
> writer.println("Es ist der " + format.format(new Date()) +
> " Uhr");
> writer.println("");
> writer.println("");
> writer.flush();
> writer.close();
> }
> protected void doPost(HttpServletRequest request, HttpServletResponse
> response) throws ServletException, IOException {
> // TODO Auto-generated method stub
> }
> }
> [/java]
>
> *WebSocketConnection*
>
> [java]package de.gfwebsocket;
> import com.sun.grizzly.tcp.Request;
> import com.sun.grizzly.websockets.WebSocket;
> import com.sun.grizzly.websockets.WebSocketApplication;
> import com.sun.grizzly.websockets.WebSocketListener;
> public class WebSocketConnection extends WebSocketApplication{
> @Override
> public WebSocket createSocket(WebSocketListener... listeners) {
> // TODO Auto-generated method stub
> return new WebSocketDataProcess(listeners);
> }
> @Override
> public void onClose(WebSocket socket) {
> // TODO Auto-generated method stub
> super.onClose(socket);
> }
> @Override
> public void onConnect(WebSocket socket) {
> // TODO Auto-generated method stub
> super.onConnect(socket);
> }
> @Override
> public void onMessage(WebSocket socket, String text) {
> socket.send(text);
> //super.onMessage(socket, text);
> }
>
>
> // return true if you want to communicate over websocket otherwise
> return false
> @Override
> public boolean isApplicationRequest(Request arg0) {
> // TODO Auto-generated method stub
> return true;
> }
> }[/java]
>
> *WebSocketDataProcess*
>
> [java]
>
> package de.gfwebsocket;
> import com.sun.grizzly.websockets.BaseServerWebSocket;
> import com.sun.grizzly.websockets.WebSocketListener;
> public class WebSocketDataProcess extends BaseServerWebSocket{
>
> public WebSocketDataProcess(WebSocketListener... listeners) {
> // TODO Auto-generated constructor stub
> super(listeners);
> }
> }[/java]
>
> I exported this project as an .war-File and deployed it in GlassFish
> via web
> console. I tried to reach it by using firefox and it showed me the actual
> time as expected.
>
> But if i try my client to connect with the websocket server, it
> failed. I get
> an exception on client side: "connection failed: unknown status code
> 200".
> My Client works with WebSocket. As i said, i tested it with a jetty
> websocket
> server implementation.
>
> So i tried to enable websockets in glassfish 3.1.1. I started the
> server with
> "./asadmin start-server" and then i tried "./asadmin set
> configs.config.server-config.network-config.protocols.protocol.http-listener-1.http.websockets-support-enabled=true".
>
> But "set" failed and it does not work.
>
>
>
> So, can anybody help me?
>
> Thank you for your help in advance.
>
> Best regards
>
> hsch
>
>
>
>
> --
>
> [Message sent by forum member 'hsch']
>
> View Post: http://forums.java.net/node/882757
>
>

hsch
Offline
Joined: 2012-01-17
Points: 0

Hi,

it works. i set the variable sucessfully. i think, i had a mistake in the command. But my application is still not working.

if i try to connect with my client, i will get an exception:

de.roderick.weberknecht.WebSocketException: connection failed: unknown status code 200
at de.roderick.weberknecht.WebSocketHandshake.verifyServerStatusLine(WebSocketHandshake.java:96)
at de.roderick.weberknecht.WebSocketConnection.connect(WebSocketConnection.java:124)
at de.wstest.WSConnection.connect(WSConnection.java:95)
at de.wstest.TestClient.<init>(TestClient.java:10)
at de.wstest.WSClient.main(WSClient.java:13)

I see in wireshark that the client sends a request with "Upgrade protocol", but the server sends "200 ok". but this is not the right answer,isn't ist?!

if i delete the doGet and doPost methods, i will get always the same exception:

de.roderick.weberknecht.WebSocketException: connection failed: unknown status code 405
at de.roderick.weberknecht.WebSocketHandshake.verifyServerStatusLine(WebSocketHandshake.java:96)
at de.roderick.weberknecht.WebSocketConnection.connect(WebSocketConnection.java:124)
at de.wstest.WSConnection.connect(WSConnection.java:95)
at de.wstest.TestClient.<init>(TestClient.java:10)
at de.wstest.WSClient.main(WSClient.java:13)

So, can you say, what i did wrong or how to fix it?

best regards

hsch

rlubke
Offline
Joined: 2003-08-21
Points: 0

On 1/17/12 8:13 AM, forums@java.net wrote:
> Hi,
>
> it works. i set the variable sucessfully. i think, i had a mistake in the
> command. But my application is still not working.
>
> if i try to connect with my client, i will get an exception:
>
> connect() failed! Reason: connection failed: unknown status code 200
> de.roderick.weberknecht.WebSocketException: connection failed: unknown
> status
> code 200
> at
> de.roderick.weberknecht.WebSocketHandshake.verifyServerStatusLine(WebSocketHandshake.java:96)
>
> at
> de.roderick.weberknecht.WebSocketConnection.connect(WebSocketConnection.java:124)
>
> at de.wstest.WSConnection.connect(WSConnection.java:95)
> at de.wstest.TestClient.(TestClient.java:10)
> at de.wstest.WSClient.main(WSClient.java:13)
>
> I see in wireshark that the client sends a request with "Upgrade
> protocol",
> but the server sends "200 ok". but this is not the right answer,isn't
> ist?!
>
>
>
> if i delete the doGet and doPost methods, i will get always the same
> exception:
>
> de.roderick.weberknecht.WebSocketException: connection failed: unknown
> status
> code 405
> at
> de.roderick.weberknecht.WebSocketHandshake.verifyServerStatusLine(WebSocketHandshake.java:96)
>
> at
> de.roderick.weberknecht.WebSocketConnection.connect(WebSocketConnection.java:124)
>
> at de.wstest.WSConnection.connect(WSConnection.java:95)
> at de.wstest.TestClient.(TestClient.java:10)
> at de.wstest.WSClient.main(WSClient.java:13)
>
>
>
> So, can you say, what i did wrong or how to fix it?
Currently, you'll need to restart the server in order for change to take
effect. Can you confirm if you did this or not (wasn't clear from
previous mails).
>
> best regards
>
> hsch
>
>
>
>
>
>
> --
>
> [Message sent by forum member 'hsch']
>
> View Post: http://forums.java.net/node/882757
>
>

hsch
Offline
Joined: 2012-01-17
Points: 0

ok. my approach was this one:

1. started the server (./asadmin start-domain)

2. enable websockets (./asadmin set ...)

3. tested with my websockets client using the weberknecht websockets

4. shut down the server (./asadmin stop-domain)

5. started the server (./asadmin start-domain)

6. enable websockets (./asadmin set ...)

7. tested again

so, are the enabled websockets stored in config persistent or had i to enable it at every start?

or is there an extra library provided by glassfish for the client that i have to use? I used weberknecht client websocket library, because they work on android. Does the (possibly) glassfish-client-websocket-library support android?

best regards

hsch

rlubke
Offline
Joined: 2003-08-21
Points: 0

On 1/17/12 10:44 AM, forums@java.net wrote:
> ok. my approach was this one:
>
> 1. started the server (./asadmin start-domain)
>
> 2. enable websockets (./asadmin set ...)
>
> 3. tested with my websockets client using the weberknecht websockets
>
> 4. shut down the server (./asadmin stop-domain)
>
> 5. started the server (./asadmin start-domain)
>
> 6. enable websockets (./asadmin set ...)
>
> 7. tested again
>
>
>
> so, are the enabled websockets stored in config persistent or had i to
> enable
> it at every start?
No. But any time you make a change (i.e., false to true or vice versa)
you'll need to restart
the server for the change to take effect.

You can verify that the option is enabled by searching for
websockets-support-enabled in the domain.xml of the domain in question.

That said, if you can provide a test case (client as well if possible)
and open an issue, we can investigate.
>
> or is there an extra library provided by glassfish for the client that
> i have
> to use? I used weberknecht client websocket library, because they work on
> android. Does the (possibly) glassfish-client-websocket-library support
> android?
>
> best regards
>
> hsch
>
>
> --
>
> [Message sent by forum member 'hsch']
>
> View Post: http://forums.java.net/node/882757
>
>

hsch
Offline
Joined: 2012-01-17
Points: 0

Ok. I made a minimal example for client and and server. I attachted it in this post. (http://www.java.net/sites/default/files/example.zip)

Can you say me, if there are extra libraries for Java websocket-clients provided by glassfish or weberknecht-websocket client libraries are not compatible in glassfish?

Here are my minimal examples:

Client (work with jetty, but not with glassfish):

package de.wsclient;

import java.net.URI;
import java.net.URISyntaxException;

import de.roderick.weberknecht.WebSocket;
import de.roderick.weberknecht.WebSocketConnection;
import de.roderick.weberknecht.WebSocketEventHandler;
import de.roderick.weberknecht.WebSocketException;
import de.roderick.weberknecht.WebSocketMessage;

public class Client {

static boolean open = true;
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

try {
// jetty url
//URI url = new URI("ws://172.30.17.110:8080/WSTest/WebServletTest");

// glassfish url
URI url = new URI("ws://172.30.17.110:8080/GlassfishWebSocket/WebSocketServlet");

WebSocket socket = new WebSocketConnection(url);

socket.setEventHandler(new WebSocketEventHandler() {

@Override
public void onOpen() {
System.out.println("Websocket opened");

}

@Override
public void onMessage(WebSocketMessage arg0) {
System.out.println(arg0.getText());
open = false;

}

@Override
public void onClose() {
System.out.println("Websockt closed");

}
});

socket.connect();

socket.send("test");

// wait for incoming messages, then close connection
while(open){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block./as
e.printStackTrace();
}
}
socket.close();

} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (WebSocketException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}

GlassFish WebSocket Servlet:

Servlet:

package de.gfwebsocket;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sun.grizzly.websockets.WebSocketEngine;

/**
* Servlet implementation class WebSocketServlet
*/
public class WebSocketServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

private final WebSocketConnection conn = new WebSocketConnection();

public WebSocketServlet() {
super();
// TODO Auto-generated constructor stub
}

public void init(ServletConfig config) throws ServletException {
// TODO Auto-generated method stub
WebSocketEngine.getEngine().register(conn);
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
PrintWriter writer = response.getWriter();
writer.println("<html>");
writer.println("<head><title>Hello World Servlet</title></head>");
writer.println("<body>");
writer.println("<h1>Es ist der " + format.format(new Date()) + " Uhr</h1>");
writer.println("<body>");
writer.println("</html>");
writer.flush();
writer.close();
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}

}

WebSocketApplication-Class:

package de.gfwebsocket;

import com.sun.grizzly.tcp.Request;
import com.sun.grizzly.websockets.WebSocket;
import com.sun.grizzly.websockets.WebSocketApplication;
import com.sun.grizzly.websockets.WebSocketListener;

public class WebSocketConnection extends WebSocketApplication{

@Override
public WebSocket createSocket(WebSocketListener... listeners) {
// TODO Auto-generated method stub
//return super.createSocket(listeners);
return new WebSocketDataProcess(listeners);
}

// @Override
// public void onClose(WebSocket socket) {
// // TODO Auto-generated method stub
// super.onClose(socket);
// }
//
// @Override
// public void onConnect(WebSocket socket) {
// // TODO Auto-generated method stub
// super.onConnect(socket);
// }

@Override
public void onMessage(WebSocket socket, String text) {
socket.send(text);
//super.onMessage(socket, text);
}

// return true if you want to communicate over websocket otherwise return false
@Override
public boolean isApplicationRequest(Request arg0) {
// TODO Auto-generated method stub
return true;
}

}

BaseServerWebSocket:

package de.gfwebsocket;

import com.sun.grizzly.websockets.BaseServerWebSocket;
import com.sun.grizzly.websockets.WebSocketListener;

public class WebSocketDataProcess extends BaseServerWebSocket{

public WebSocketDataProcess(WebSocketListener... listeners) {
// TODO Auto-generated constructor stub
super(listeners);
}
}

My approach for this examples:

1. ./asadmin start-domain

2. ./asadmin set configs.config.server-config.network-config.protocols.protocol.http-listener-1.http.websockets-support-enabled=true

3. ./asadmin stop-domain

4. ./asadmin start-domain

5. run the client

thank you for your help in advance

best regards

hsch

hsch
Offline
Joined: 2012-01-17
Points: 0

hey,

i only would like to know if there are extra libraries for Java websocket-clients provided by glassfish or weberknecht-websocket client libraries are not compatible in glassfish?

Thank you for your help in advance.

best regards

hsch

rlubke
Offline
Joined: 2003-08-21
Points: 0

On 1/18/12 11:35 PM, forums@java.net wrote:
> hey,
>
> i only would like to know if there are extra libraries for Java
> websocket-clients provided by glassfish or weberknecht-websocket client
> libraries are not compatible in glassfish?
I hope to dig further into your issue today. As to your question, no,
there are no
additional client libraries needed to work with GlassFish.

>
> Thank you for your help in advance.
>
> best regards
>
> hsch
>
>
> --
>
> [Message sent by forum member 'hsch']
>
> View Post: http://forums.java.net/node/882757
>
>

hsch
Offline
Joined: 2012-01-17
Points: 0

Oh thank you very much. That sounds very good and would be great, if it works! :D

I will wait eagerly for your answer (solution).

So far, best regards

hsch

rlubke
Offline
Joined: 2003-08-21
Points: 0

On 1/19/12 11:33 AM, forums@java.net wrote:
> Oh thank you very much. That sounds very good and would be great, if
> it work!
> :D
Ok, looking at the client library you're trying to use, it's based of
hybi-00. The version of Grizzly in 3.1.1 appears to support a later
version. There was refactoring after that Grizzly release to expand
the range of supported protocol versions.

While I'm getting setup on this end, I'd like to recommend your trying a
promoted build of GlassFish 3.1.2 [1].
This release contains the latest WebSocket implementation for Grizzly
1.9 and supports multiple versions.

[1] http://www.java.net/external?url=http://dlc.sun.com.edgesuite.net/glassfish/3.1.2/promoted/

>
> I will wait eagerly for your answer (solution).
>
>
>
> So far, best regards
>
> hsch
>
>
> --
>
> [Message sent by forum member 'hsch']
>
> View Post: http://forums.java.net/node/882757
>
>

hsch
Offline
Joined: 2012-01-17
Points: 0

hey rlubke,

i will give glassfish 3.1.2. but i have a seeming well-know issue with the login in the admin console. I downloaded the

<a name="latest-glassfish-ml.zip"href="http://dlc.sun.com.edgesuite.net/glassfish/3.1.2/promoted/latest-glassfish-ml.zip">  latest-glassfish-ml.zip</a>

from http://www.java.net/external?url=http://dlc.sun.com.edgesuite.net/glassf... and started it normally. But i have a problem with the login. What is the user and password to login into the admin console from a remote host? I tried "admin" as user and leave the password field empty.

Follwoing failure appears:

"

"

I browsed the forum and find a pissibly solution, which does not work. If i try "./asadmin enable-secure-admin", the following failure appears:

~/servervm/gf/glassfish3/bin$ ./asadmin enable-secure-admin
remote failure: At least one admin user has an empty password, which secure admin does not permit. Use the change-admin-password command or the admin console to create non-empty passwords for admin accounts.
Befehl enable-secure-admin war nicht erfolgreich.

So i tried the "change-admin-password command", but with no success:

./asadmin change-admin-password
Admin-Benutzernamen eingeben [Standard: admin]> admin
Admin-Kennwort eingeben> *leave empty - only press enter*
Neues Admin-Kennwort eingeben> *new password*
Neues Admin-Kennwort erneut eingeben> *new password*
Befehl change-admin-password wurde erfolgreich ausgeführt.
After that, i stopped the domain and restartet it and try to login with "admin" and my new password, BUT NO SUCCESS! it is depressing. :(

best reagards

hsch

hsch
Offline
Joined: 2012-01-17
Points: 0

Ok, the Problem with log into the admin console solved.

Logged in on localhost, changed the admin password, activate secure administration and wait for restart. Afetr that i can login with "admin" and my new password.

I will report, if my websocket client will work with gthe new glassfish version (3.1.2-b18 (build 18)).

hsch
Offline
Joined: 2012-01-17
Points: 0

Ok. It deployed the server application and tested the client and i always get the same error

de.roderick.weberknecht.WebSocketException: connection failed: unknown status code 200
at de.roderick.weberknecht.WebSocketHandshake.verifyServerStatusLine(WebSocketHandshake.java:96)
at de.roderick.weberknecht.WebSocketConnection.connect(WebSocketConnection.java:124)
at de.wstest.WSConnection.connect(WSConnection.java:96)
at de.wstest.TestClient.<init>(TestClient.java:10)
at de.wstest.WSClient.main(WSClient.java:13)

It is very sad. I try to find another client library which i can use for android. Or do you know a compatible android library?

best regards and thank you for your help

hsch

rlubke
Offline
Joined: 2003-08-21
Points: 0

OK, I was able to reproduce the issue against 3.1.2. When I tested the issue, the first time the client is run, a 200 is returned (with content as genered by doGet() in your servlet), but if I ran the client a second time, then it would work as expected. The reason for this is because at the time of the first request the Servlet that performs the WebSocket application initialization hadn't been instantiated yet. To work around this, I simply marked the servlet to be loaded at startup. After doing so, the client was able to make the ws connection on the first attempt.

Additionally, there are some API differences between the WS code in 3.1.1 and 3.1.2. I've made the changes to your server-side code and have re-attached them here (as a maven project for convenience). Using that project, you'll need to update the client to connect to the url: ws://localhost:8080/test-1.0-SNAPSHOT/test.

Let us know how this goes.

-rl

hsch
Offline
Joined: 2012-01-17
Points: 0

hey,

i implemented your suggestions to my code: changed the libraries, updated my classes and set the load-on-startup "flag" in web.xml (i know, gf3 supports servlet 3.0) and it WORKS!!!

thank you very, very much for your great help! :D

But i still have one question:

In jetty: if a request arrives, the servlet delegates the request to the doWebSocketConnect()-Method. If there are many requests, every new request get its instiated class (alias serversocket)

How is that in glassfish?

Every time a request arrive, the servlet delegate the request to "conn"-Object, which on his part executes the "createWebSocket"-Method and create a Websocket for this specific request. If there are more than one request, is this method responsible to create a websocket (server side socket) for every request?

if the socket aswers, it delegates the events to the "conn"-Object (onMessage etc.). So if there are multiple requests, are the onMessage, onOpen etc. Methods threadsafe?

For Example:

Client 1 sends a request

Client 2 sens a request (at the same time)

conn creates a websocket for C1

(the same?) conn creates a websocket for C2

Do both sockets use the same onOpen, onMessage Methods or do they have their own methods?

i hope, you understand my question /issue ;)

best regards

hsch

rlubke
Offline
Joined: 2003-08-21
Points: 0

On 1/20/12 8:01 AM, forums@java.net wrote:
> hey,
>
> i implemented your suggestions to my code: changed the libraries,
> updated my
> classes and set the load-on-startup "flag" in web.xml (i know, gf3
> supports
> servlet 3.0) and it WORKS!!!
>
> thank you very, very much for your great help! :D
>
> But i still have one question:
>
> In jetty: if a request arrives, the servlet delegates the request to the
> doWebSocketConnect()-Method. If there are many requests, every new
> request
> get its instiated class (alias serversocket)
>
> How is that in glassfish?
>
> Every time a request arrive, the servlet delegate the request to
> "conn"-Object, which on his part executes the "createWebSocket"-Method
> and
> create a Websocket for this specific request. If there are more than one
> request, is this method responsible to create a websocket (server side
> socket) for every request?
It will create a new WebSocket for each distinct upgrade request.
>
> if the socket aswers, it delegates the events to the "conn"-Object
> (onMessage
> etc.). So if there are multiple requests, are the onMessage, onOpen etc.
> Methods threadsafe?
>
> For Example:
>
> Client 1 sends a request
>
> Client 2 sens a request (at the same time)
>
> conn creates a websocket for C1
>
> (the same?) conn creates a websocket for C2
>
> Do both sockets use the same onOpen, onMessage Methods or do they have
> their
> own methods?
Each socket instance is separate.
>
> i hope, you understand my question /issue ;)
>
>
>
> best regards
>
> hsch
>
>
> --
>
> [Message sent by forum member 'hsch']
>
> View Post: http://forums.java.net/node/882757
>
>

hsch
Offline
Joined: 2012-01-17
Points: 0

ok. thank you very much again :D

best regards

hsch

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值