> For the complete documentation index, see [llms.txt](https://www.socketio4j.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.socketio4j.org/example-projects/sample-projects/emergency-broadcast-app.md).

# Emergency broadcast app

## Server

```java
import com.socketio4j.socketio.Configuration;
import com.socketio4j.socketio.SocketIOServer;
import com.socketio4j.socketio.SocketIOClient;

public class EmergencyServer {
    public static void main(String[] args) {
        Configuration config = new Configuration();
        config.setHostname("localhost");
        config.setPort(9092);

        SocketIOServer server = new SocketIOServer(config);

        // Event: broadcast emergency messages
        server.addEventListener("emergency", String.class,
            (SocketIOClient client, String message, var ack) -> {
            // print locally
            log.info("EMERGENCY message received: {}", message);

            // send to all clients
            server.getBroadcastOperations().sendEvent("emergency", message);
        });

        server.start();
        log.info("Emergency server started on :9092");
    }
}

```

## Client

```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Emergency Alert Client</title>
</head>

<body>
  <h1>🚨 Emergency Alert Listener</h1>
  <p>Status: <span id="status">Connecting...</span></p>

  <!-- Socket.IO client -->
  <script src="https://cdn.socket.io/4.7.5/socket.io.min.js"></script>

  <script>
    const statusEl = document.getElementById("status");
    const socket = io("http://localhost:9092");

    socket.on("connect", () => {
      statusEl.innerText = "Connected";
      console.log("Connected to emergency server");
    });

    // listen for emergency alert broadcasts
    socket.on("emergency", msg => {
      console.log("Emergency alert received:", msg);
      alert("🚨 Emergency: " + msg);
    });

    socket.on("disconnect", () => {
      statusEl.innerText = "Disconnected";
    });
  </script>

</body>
</html>

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.socketio4j.org/example-projects/sample-projects/emergency-broadcast-app.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
