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

# Documentation Socketio4j

Bienvenue sur la plateforme de développement de votre équipe

<h2 align="center">Le projet Socketio4j</h2>

<p align="center">Serveur Socket.IO implémenté en Java. Framework Java en temps réel</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>Pour commencer</strong></td><td>Commencez avec le serveur socketio en 5 minutes.</td><td><a href="https://www.socketio4j.org/installation/installation-fr/">français</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>API serveur</strong></td><td>En savoir plus sur l'API du serveur Socketio</td><td><a href="https://www.socketio4j.org/server-api/server-api-4.0-fr/">français</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>Exemples</strong></td><td>Exemples pour explorer le serveur socketio en Java core, Spring Boot, Quarkus et 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>

### Commencer en 5 minutes

Votre premier serveur devrait être l'étape la plus simple. Avec des points de terminaison bien définis et des exemples prêts à copier-coller, la configuration est rapide et prévisible.\
De zéro à une connexion fonctionnelle en quelques minutes.

<a href="https://www.socketio4j.org/installation/installation-fr/" class="button primary" data-icon="rocket-launch">Commencer</a> <a href="https://www.socketio4j.org/server-api/server-api-4.0-fr/" class="button secondary" data-icon="terminal">Référence API</a>

### Serveur

{% tabs %}
{% tab title="Java Core" %}
{% 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());

            // Rejoindre une salle via paramètre de requête : ?room=room1, vérifier l'appartenance à la salle si nécessaire
            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);

                    // Diffuser à tous les clients
                    server.getBroadcastOperations()
                          .sendEvent("message", data);

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

        server.start();
        System.out.println("Serveur SocketIO4J démarré sur :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="Navigateur - JS Vanilla" %}
{% 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">Rejoignez une communauté croissante, bâtie sur une base approuvée par <strong>plus de 7 000 développeurs</strong></h2>

<p align="center">Rejoignez notre communauté Discord ou créez votre première PR en quelques étapes.</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">Image de couverture</th></tr></thead><tbody><tr><td><h4><i class="fa-discord">:discord:</i></h4></td><td><strong>Communauté Discord</strong></td><td>Rejoignez notre communauté Discord pour poser des questions, obtenir de l'aide et partager des ressources avec plus de 7 000 développeurs curieux partageant les mêmes idées.</td><td><a href="https://discord.gg/5TFTQJXR" class="button secondary" data-icon="discord">Rejoindre Discord</a></td><td></td></tr><tr><td><h4><i class="fa-github">:github:</i></h4></td><td><strong>GitHub</strong></td><td>Notre produit est 100 % open source et développé par des développeurs comme vous. Rendez-vous sur notre dépôt GitHub pour apprendre comment soumettre votre première PR.</td><td><a href="https://github.com/socketio4j/netty-socketio/pulls" class="button secondary" data-icon="sandwich">Soumettre une PR</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-fr/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.
