> 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
