> 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/home/home-de/home.md).

# Socketio4j-Dokumentation

Willkommen auf der Entwicklerplattform Ihres Teams

<h2 align="center">Das Socketio4j-Projekt</h2>

<p align="center">Socket.IO-Server implementiert in Java. Echtzeit-Java-Framework</p>

<table data-view="cards"><thead><tr><th></th><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th><th data-hidden data-card-cover data-type="files"></th></tr></thead><tbody><tr><td><h4><i class="fa-leaf">:leaf:</i></h4></td><td><strong>Erste Schritte</strong></td><td>Starten Sie den SocketIO-Server in 5 Minuten.</td><td><a href="https://www.socketio4j.org/installation/installation-de/">Deutsch</a></td><td><a href="https://content.gitbook.com/content/JM9bJrLGqbzxSZf83Icn/blobs/POOywUuQh7zjLkUbwb4v/no-code.jpg">no-code.jpg</a></td></tr><tr><td><h4><i class="fa-server">:server:</i></h4></td><td><strong>Server-API</strong></td><td>Erfahren Sie mehr über die Socketio-Server-API</td><td><a href="https://www.socketio4j.org/server-api/server-api-4.0-de/">Deutsch</a></td><td><a href="https://content.gitbook.com/content/JM9bJrLGqbzxSZf83Icn/blobs/PtapuaiPaO4WUsJcgHDP/hosted.jpg">hosted.jpg</a></td></tr><tr><td><h4><i class="fa-terminal">:terminal:</i></h4></td><td><strong>Beispiele</strong></td><td>Beispiele zum Erkunden des SocketIO-Servers in Core Java, Spring Boot, Quarkus und Micronaut</td><td><a href="https://www.socketio4j.org/example-projects/">Examples</a></td><td><a href="https://content.gitbook.com/content/JM9bJrLGqbzxSZf83Icn/blobs/sG2Zw2nxI6FxNgJXX3ec/api-reference.jpg">api-reference.jpg</a></td></tr></tbody></table>

### In 5 Minuten loslegen

Ihr erster Server sollte der einfachste Schritt sein. Mit gut definierten Endpunkten und zum Kopieren bereiten Beispielen ist die Einrichtung schnell und vorhersehbar.\
Von null zu einer funktionierenden Verbindung in Minuten.

<a href="https://www.socketio4j.org/installation/installation-de/" class="button primary" data-icon="rocket-launch">Loslegen</a> <a href="https://www.socketio4j.org/server-api/server-api-4.0-de/" class="button secondary" data-icon="terminal">API-Referenz</a>

### Server

{% tabs %}
{% tab title="Core Java" %}
{% code title="Server.java" overflow="wrap" expandable="true" %}

```java

//package com.socketio4j.examples.core;

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

public final class BasicServer {

    public static void main(String[] args) {

        Configuration config = new Configuration();
        config.setHostname("0.0.0.0");
        config.setPort(9092);

        SocketIOServer server = new SocketIOServer(config);

        server.addConnectListener(client -> {
            System.out.println("Connected: " + client.getSessionId());

            // Join room via query param: ?room=room1, verify room membership if needed
            String room = client.getHandshakeData()
                    .getSingleUrlParam("room");

            if (room != null) {
                client.joinRoom(room);
                System.out.println("Joined room: " + room);
            }
        });

        server.addDisconnectListener(client ->
                System.out.println("Disconnected: " + client.getSessionId())
        );

        server.addEventListener(
                "message",
                String.class,
                (SocketIOClient client, String data, var ack) -> {

                    System.out.println("Received: " + data);

                    // Broadcast to all clients
                    server.getBroadcastOperations()
                          .sendEvent("message", data);

                    ack.sendAckData("ok");
                }
        );

        server.start();
        System.out.println("SocketIO4J server started on :9092");

        Runtime.getRuntime().addShutdownHook(
                new Thread(server::stop)
        );
    }
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Client

{% tabs %}
{% tab title="Java" %}
{% code title="Client.java
" overflow="wrap" expandable="true" %}

```java
//package com.socketio4j.examples.core;

import io.socket.client.IO;
import io.socket.client.Socket;

import java.net.URISyntaxException;
import java.util.Collections;

public class SocketIoClient {

    public static void main(String[] args) throws URISyntaxException {

        IO.Options options = new IO.Options();
        options.query = "room=room1";
        options.forceNew = true;

        Socket socket = IO.socket("http://localhost:9092", options);

        socket.on(Socket.EVENT_CONNECT, args1 -> {
            System.out.println("Connected: " + socket.id());
            socket.emit("message", "Hello from Java");
        });

        socket.on("message", args1 ->
                System.out.println("Received: " + args1[0])
        );

        socket.connect();
    }
}

```

{% endcode %}
{% endtab %}

{% tab title="node.js" %}
{% code title="client.js" overflow="wrap" expandable="true" %}

```javascript
import { io } from "socket.io-client";

const socket = io("http://localhost:9092", {
  query: { room: "room1" }
});

socket.on("connect", () => {
  console.log("Connected:", socket.id);
  socket.emit("message", "Hello from Node.js");
});

socket.on("message", (data) => {
  console.log("Received:", data);
});

```

{% endcode %}
{% endtab %}

{% tab title="Dart / Flutter" %}
{% code overflow="wrap" expandable="true" %}

```dart
import 'package:socket_io_client/socket_io_client.dart' as IO;

void main() {
  IO.Socket socket = IO.io(
    'http://localhost:9092',
    IO.OptionBuilder()
        .setQuery({'room': 'room1'})
        .setTransports(['websocket'])
        .build(),
  );

  socket.onConnect((_) {
    print('Connected: ${socket.id}');
    socket.emit('message', 'Hello from Dart');
  });

  socket.on('message', (data) {
    print('Received: $data');
  });
}

```

{% endcode %}
{% endtab %}

{% tab title="Swift (iOS)" %}
{% code overflow="wrap" expandable="true" %}

```swift
import SocketIO

let manager = SocketManager(
    socketURL: URL(string: "http://localhost:9092")!,
    config: [.log(true), .connectParams(["room": "room1"])]
)

let socket = manager.defaultSocket

socket.on(clientEvent: .connect) { _, _ in
    print("Connected:", socket.sid ?? "")
    socket.emit("message", "Hello from Swift")
}

socket.on("message") { data, _ in
    print("Received:", data[0])
}

socket.connect()

```

{% endcode %}
{% endtab %}

{% tab title="Browser - Vanilla JS" %}
{% code overflow="wrap" expandable="true" %}

```html
<script src="https://cdn.socket.io/4.7.5/socket.io.min.js"></script>
<script>
  const socket = io("http://localhost:9092", {
    query: { room: "room1" }
  });

  socket.on("connect", () => {
    console.log("Connected:", socket.id);
    socket.emit("message", "Hello from Browser");
  });

  socket.on("message", (data) => {
    console.log("Received:", data);
  });
</script>

```

{% endcode %}
{% endtab %}

{% tab title="Python" %}
{% code title="client.py" overflow="wrap" expandable="true" %}

```py
import socketio

sio = socketio.Client()

@sio.event
def connect():
    print("Connected:", sio.sid)
    sio.emit("message", "Hello from Python")

@sio.on("message")
def on_message(data):
    print("Received:", data)

sio.connect("http://localhost:9092?room=room1")
sio.wait()

```

{% endcode %}
{% endtab %}

{% tab title="C# (.NET)" %}
{% code overflow="wrap" expandable="true" %}

```csharp
using SocketIOClient;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        var client = new SocketIO("http://localhost:9092", new SocketIOOptions
        {
            Query = new[],
                new KeyValuePair<string, string>("room", "room1")
            }
        });

        client.OnConnected += async (sender, e) =>
        {
            Console.WriteLine($"Connected: {client.Id}");
            await client.EmitAsync("message", "Hello from C#");
        };

        client.On("message", response =>
        {
            Console.WriteLine("Received: " + response.GetValue<string>());
        });

        await client.ConnectAsync();
        await Task.Delay(-1);
    }
}

```

{% endcode %}
{% endtab %}

{% tab title="Go" %}
{% code overflow="wrap" expandable="true" %}

```go
package main

import (
	"fmt"
	socketio "github.com/zhouhui8915/go-socket.io-client"
)

func main() {

	opts := &socketio.Options{
		Query: map[string]string{
			"room": "room1",
		},
	}

	client, err := socketio.NewClient("http://localhost:9092", opts)
	if err != nil {
		panic(err)
	}

	client.On("connect", func() {
		fmt.Println("Connected")
		client.Emit("message", "Hello from Go")
	})

	client.On("message", func(msg string) {
		fmt.Println("Received:", msg)
	})

	select {}
}

```

{% endcode %}
{% endtab %}

{% tab title="Rust" %}
{% code overflow="wrap" expandable="true" %}

```rs
use rust_socketio::{ClientBuilder, Payload};

fn main() {
    let client = ClientBuilder::new("http://localhost:9092")
        .query("room", "room1")
        .on("connect", |_, _| {
            println!("Connected");
        })
        .on("message", |payload, _| {
            if let Payload::String(msg) = payload {
                println!("Received: {}", msg);
            }
        })
        .connect()
        .expect("Connection failed");

    client.emit("message", "Hello from Rust").unwrap();
    loop {}
}

```

{% endcode %}
{% endtab %}
{% endtabs %}

<h2 align="center">Schließen Sie sich einer wachsenden Community an, die auf einem von vertrauenswürdigen Grundlagen aufgebaut ist <strong>7.000+ Entwicklern</strong></h2>

<p align="center">Treten Sie unserer Discord-Community bei oder erstellen Sie in nur wenigen Schritten Ihren ersten PR.</p>

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th></th><th></th><th></th><th data-hidden data-card-cover data-type="image">Titelbild</th></tr></thead><tbody><tr><td><h4><i class="fa-discord">:discord:</i></h4></td><td><strong>Discord-Community</strong></td><td>Treten Sie unserer Discord-Community bei, um Fragen zu stellen, Hilfe zu erhalten und Ressourcen mit über 7.000 gleichgesinnten neugierigen Entwicklern zu teilen.</td><td><a href="https://discord.gg/5TFTQJXR" class="button secondary" data-icon="discord">Tritt Discord bei</a></td><td></td></tr><tr><td><h4><i class="fa-github">:github:</i></h4></td><td><strong>GitHub</strong></td><td>Unser Produkt ist 100% Open Source und wird von Entwicklern wie Ihnen erstellt. Gehen Sie zu unserem GitHub-Repository, um zu erfahren, wie Sie Ihren ersten PR einreichen.</td><td><a href="https://github.com/socketio4j/netty-socketio/pulls" class="button secondary" data-icon="sandwich">Einen PR einreichen</a></td><td></td></tr></tbody></table>


---

# 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/home/home-de/home.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.
