1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
		Server server = new Server(8080);
		server.setHandler(new AbstractHandler() {

			@Override
			public void handle(String target, Request baseRequest,
					HttpServletRequest request, HttpServletResponse response)
					throws IOException, ServletException {

				response.setContentType("text/plain;charset=utf-8");
				PrintWriter pw = response.getWriter();
				String json = "{\"foo\" : \"bar\"}\n\r\n";
				try {
					while (true) {
						pw.write(json);
						pw.flush();
						try {
							Thread.sleep(250);
						} catch (InterruptedException e) {
						}
					}
				} catch (Exception e) {
					e.printStackTrace();
				}

				System.out.println("Out of while()");

			}
		});

		server.start();
		server.join();