-
-
Notifications
You must be signed in to change notification settings - Fork 751
Using the build in WebSocket Protocol
jfarcand edited this page Sep 14, 2012
·
3 revisions
When using WebSockets, you can enable a really simple WebSocket Sub-Protocol to pass, along with a WebSocket messages, some URI which are used by Atmosphere to dispatch to the appropriate resource. The first steps is to enable the sub-protocol on the SimpleHttpProtocol:
<init-param>
<param-name>org.atmosphere.websocket.pathDelimiter</param-name>
<param-value>@@</param-value>
</init-param>
The path can be any character and that will be used to find the websocket message. On the client side, you enable it by doing:
var request = { url: document.location.toString() + 'chat',
webSocketUrl : '/a URI relative to the url value',
webSocketPathDelimiter : "@@" }
};
For example,
var request = { url: document.location.toString() + 'chat',
webSocketUrl : '/room1',
webSocketPathDelimiter : "@@" }
Doing:
var subSock = $.atmosphere.subscribe(request);
subSock.push("hello room1");
will match the @Post method of:
@Path("/chat")
public class ResourceChat {
@Suspend(contentType = "application/json")
@GET
public String suspend() {
return "";
}
@Broadcast(writeEntity = false)
@POST
@Path("/room1")
@Produces("application/json")
public Response broadcast(Message message) {
return new Response(message.author, message.message);
}
}
- Understanding Atmosphere
- Understanding @ManagedService
- Using javax.inject.Inject and javax.inject.PostConstruct annotation
- Understanding Atmosphere's Annotation
- Understanding AtmosphereResource
- Understanding AtmosphereHandler
- Understanding WebSocketHandler
- Understanding Broadcaster
- Understanding BroadcasterCache
- Understanding Meteor
- Understanding BroadcastFilter
- Understanding Atmosphere's Events Listeners
- Understanding AtmosphereInterceptor
- Configuring Atmosphere for Performance
- Understanding JavaScript functions
- Understanding AtmosphereResourceSession
- Improving Performance by using the PoolableBroadcasterFactory
- Using Atmosphere Jersey API
- Using Meteor API
- Using AtmosphereHandler API
- Using Socket.IO
- Using GWT
- Writing HTML5 Server-Sent Events
- Using STOMP protocol
- Streaming WebSocket messages
- Configuring Atmosphere's Classes Creation and Injection
- Using AtmosphereInterceptor to customize Atmosphere Framework
- Writing WebSocket sub protocol
- Configuring Atmosphere for the Cloud
- Injecting Atmosphere's Components in Jersey
- Sharing connection between Browser's windows and tabs
- Understanding AtmosphereResourceSession
- Manage installed services
- Server Side: javadoc API
- Server Side: atmosphere.xml and web.xml configuration
- Client Side: atmosphere.js API