Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Sending data over the server end of a WebSocket

this link has a sample Jetty WebSocketServlet: http://blogs.webtide.com/gregw/entry/jetty_websocket_server

I am using Spring framework for my web server, so naturally I created a service layer:

@Service
public class WebSocketService {
private final Set<MyWebSocket> _members = new CopyOnWriteArraySet<MyWebSocket>();
        .....
public WebSocket getWebSocket () {
return new MyWebSocket ();
}

public void sendData (String data) {
if (!_members.isEmpty()) {
MyWebSocket socket = _members.iterator().next();
socket.onMessage((byte)0, data);
}
}

class MyWebSocket implements WebSocket {
Outbound _outbound;
                ......
@Override
public void onMessage(byte frame, String data) {
.......
}
        }
}

For WebSocket client, I do not need to handle anything - servlet will get an instance of MyWebSocket, and when data comes in, onMessage() will be invoked automatically. 

For my JMS client, once my JMS end point get the data, it calls sendData(), which get one instance of WebSocket and call onMessage() manually. This looks pretty brute to me. But I do not know any other ways to support JMS clients.
 
rgds,
canal



From: Erin Drummond <erin.dru@xxxxxxxxx>
To: JETTY user mailing list <jetty-users@xxxxxxxxxxx>
Sent: Mon, January 18, 2010 4:25:09 PM
Subject: Re: [jetty-users] Sending data over the server end of a WebSocket

That was the WebSocket client I was using originally, but I used it as
a base and rewrote it using xSocket for my purposes. It actually
worked really well though.

In the server, you have to create a WebSocketServlet. It spawns
WebSocket objects which, when connected, have an Outbound object you
can use to send messages back to the client.

Details here: http://blogs.webtide.com/gregw/entry/jetty_websocket_server

On Mon, Jan 18, 2010 at 6:29 PM, go canal <gocanal@xxxxxxxxx> wrote:
> Hi,
> I also just started playing around with WebSocket. I have not tried more
> than 3kb.
> Sorry, I do not have answers for your questions. But rather, I have a couple
> of questions:
>  - which WebSocket java client library are you using ?
>     I find this : http://github.com/adamac/Java-WebSocket-client but have
> not tried it.
>  - I have a server supporting WebSocket and JMS; Anther program send data to
> the server using JMS; all clients connect to the server using WebSocket. In
> the server, how do I pass JMS messages to WebSocket ?
>
> rgds,
> canal
>
> ________________________________
> From: Erin Drummond <erin.dru@xxxxxxxxx>
> To: jetty-users@xxxxxxxxxxx
> Sent: Mon, January 18, 2010 10:56:44 AM
> Subject: [jetty-users] Sending data over the server end of a WebSocket
>
> Hi,
>
> I am trying to get communications between two Java programs using a
> Websocket. One has an embedded Jetty server running a WebSocketServlet
> instance, and the other has a java implementation of a WebSocket
> client.
>
> The client can connect to the server and send data, and the server can
> send data back to the client through the Outbound object. This works
> fine for messages smaller than 3 kilobytes.
>
> However, I would like to send messages much larger than that (they
> contain base64-encoded binary data). If I try and send a message
> larger than 3 kilobytes, I get:
> java.lang.IllegalArgumentException: frame too large
>         at
> org.eclipse.jetty.websocket.WebSocketGenerator.addFrame(WebSocketGenerator.java:91)
>
> Since the limit of a WebSocket frame seems to be 3kb, how can I break
> up a message and send it in multiple frames? Actually I dont really
> understand the frame thing very well, as you can specify any number
> for the frame (and the same number multiple times) and the message
> still reaches the other end in exactly the same way. In my
> understanding, a frame should be a "chunk" of data, but then why can
> the user specify a number for it? You'd think that the underlying
> network would take care of chunking up the data as it does for a
> standard TCP socket..
>
> Can somebody please help me?
>
> Cheers,
> Erin
> _______________________________________________
> jetty-users mailing list
> jetty-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/jetty-users
>
>
> _______________________________________________
> jetty-users mailing list
> jetty-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/jetty-users
>
>
_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-users


Back to the top