Skip to content

Instantly share code, notes, and snippets.

@nowelium
Created August 11, 2010 02:58
Show Gist options
  • Save nowelium/518400 to your computer and use it in GitHub Desktop.
Save nowelium/518400 to your computer and use it in GitHub Desktop.
//
// Atmosphere example: Hello world
//
package sample.hoge;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.atmosphere.annotation.Broadcast;
import org.atmosphere.annotation.Suspend;
import com.sun.jersey.spi.resource.Singleton;
@Path("/hello")
@Singleton
@Produces("text/plain")
public class Hello {
@Path("/wait")
@Suspend(resumeOnBroadcast=true)
@GET
public String getMessage(){
return "hello world";
}
@Path("/done")
@Broadcast
@GET
public String publish(){
return "hoge";
}
}
public class Server {
public static void main(String...args){
try {
org.atmosphere.grizzly.AtmosphereSpadeServer.build("http://0.0.0.0:8080/", "sample.hoge").start();
} catch(Exception e){
e.printStackTrace();
}
}
}
[FIRST CLIENT]
client 1 > curl http://localhost:8080/hello/wait
client 1 > : (...waiting)
[NEW CLIENT]
client 2 > curl http://localhost:8080/hello/done [ENTER]
{syn} client 1 > hello world (...response text)
{syn} client 2 > hoge (...response text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment