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

# Documentación de Socketio4j

Bienvenido a la plataforma de desarrollo de tu equipo

<h2 align="center">El proyecto Socketio4j</h2>

<p align="center">Servidor Socket.IO implementado en Java. Framework de Java en tiempo real</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>Comenzando</strong></td><td>Comienza con el servidor socketio en 5 minutos.</td><td><a href="https://www.socketio4j.org/installation/installation-es/">español</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 del servidor</strong></td><td>Aprende más sobre la API del servidor Socketio</td><td><a href="https://www.socketio4j.org/server-api/server-api-4.0-es/">español</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>Ejemplos</strong></td><td>Ejemplos para explorar el servidor socketio en Java core, Spring Boot, Quarkus y 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>

### Comienza en 5 minutos

Tu primer servidor debería ser el paso más sencillo. Con endpoints bien definidos y ejemplos listos para copiar y pegar, la configuración es rápida y predecible.\
De cero a una conexión funcional en minutos.

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

### Servidor

{% tabs %}
{% tab title="Java básico" %}
{% 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 %}

### Cliente

{% 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="Navegador - JS puro" %}
{% 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">Únete a una comunidad en crecimiento, construida sobre una base en la que confían <strong>más de 7.000 desarrolladores</strong></h2>

<p align="center">Únete a nuestra comunidad de Discord o crea tu primer PR en solo unos pasos.</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">Imagen de portada</th></tr></thead><tbody><tr><td><h4><i class="fa-discord">:discord:</i></h4></td><td><strong>Comunidad de Discord</strong></td><td>Únete a nuestra comunidad de Discord para publicar preguntas, obtener ayuda y compartir recursos con más de 7.000 desarrolladores curiosos con intereses similares.</td><td><a href="https://discord.gg/5TFTQJXR" class="button secondary" data-icon="discord">Unirse a Discord</a></td><td></td></tr><tr><td><h4><i class="fa-github">:github:</i></h4></td><td><strong>GitHub</strong></td><td>Nuestro producto es 100% de código abierto y está construido por desarrolladores como tú. Visita nuestro repositorio en GitHub para aprender cómo enviar tu primer PR.</td><td><a href="https://github.com/socketio4j/netty-socketio/pulls" class="button secondary" data-icon="sandwich">Enviar un 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-es/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.
