Created
August 11, 2010 02:58
-
-
Save nowelium/518400 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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