> For the complete documentation index, see [llms.txt](https://docs.lsports.eu/u/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lsports.eu/u/defend/websocket-connection/code-examples.md).

# Code Examples

Complete code examples for connecting to the RMS-Socket WebSocket service.

## JavaScript / Node.js

```javascript
const io = require("socket.io-client");

const SERVER_URL = "wss://rms.lsports.eu";
const CUSTOMER_ID = "YOUR_CUSTOMER_ID";
const ACCESS_TOKEN = "YOUR_ACCESS_TOKEN";

const socket = io(SERVER_URL, {
  path: "/rms-socket/socket.io",
  transports: ["websocket", "polling"],
  extraHeaders: {
    Authorization: `Bearer ${ACCESS_TOKEN}`,
    customerid: CUSTOMER_ID,
  },
  reconnection: true,
  reconnectionAttempts: 10,
  reconnectionDelay: 1000,
});

// Connection events
socket.on("connect", () => {
  console.log("Connected:", socket.id);
  socket.emit("join", {}, (response) => {
    console.log("Room:", response.room);
  });
});

socket.on("connect_error", (error) => {
  console.error("Connection failed:", error.message);
});

socket.on("disconnect", (reason) => {
  console.log("Disconnected:", reason);
});

socket.on("reconnect", () => {
  console.log("Reconnected");
  socket.emit("join", {});
});

// Business events
socket.on("RESERVE_BET_ACCEPT", (data) => {
  console.log("Bet accepted:", data);
});

socket.on("RESERVE_BET_REJECT", (data) => {
  console.log("Bet rejected:", data);
});

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

***

## Python

```python
import socketio

SERVER_URL = "wss://rms.lsports.eu"
CUSTOMER_ID = "YOUR_CUSTOMER_ID"
ACCESS_TOKEN = "YOUR_ACCESS_TOKEN"

sio = socketio.Client()

@sio.event
def connect():
    print("Connected!")
    sio.emit("join", {}, callback=on_join)

def on_join(response):
    print(f"Joined room: {response['room']}")

@sio.event
def connect_error(error):
    print(f"Connection failed: {error}")

@sio.event
def disconnect():
    print("Disconnected")

@sio.on("RESERVE_BET_ACCEPT")
def on_bet_accept(data):
    print(f"Bet accepted: {data}")

@sio.on("RESERVE_BET_REJECT")
def on_bet_reject(data):
    print(f"Bet rejected: {data}")

sio.connect(
    SERVER_URL,
    socketio_path="/rms-socket/socket.io",
    transports=["websocket", "polling"],
    headers={
        "Authorization": f"Bearer {ACCESS_TOKEN}",
        "customerid": CUSTOMER_ID,
    }
)

sio.wait()
```

***

## Browser

```html
<script src="https://cdn.socket.io/4.0.0/socket.io.min.js"></script>
<script>
const socket = io("wss://rms.lsports.eu", {
  path: "/rms-socket/socket.io",
  transports: ["websocket", "polling"],
  extraHeaders: {
    Authorization: "Bearer YOUR_ACCESS_TOKEN",
    customerid: "YOUR_CUSTOMER_ID",
  },
});

socket.on("connect", () => {
  console.log("Connected:", socket.id);
  socket.emit("join", {}, (response) => {
    console.log("Room:", response.room);
  });
});

socket.on("RESERVE_BET_ACCEPT", (data) => {
  console.log("Bet accepted:", data);
  // Update your UI here
});

socket.on("connect_error", (error) => {
  console.error("Error:", error.message);
});
</script>
```

***

## Related

* [Quick Start & Best Practices](/u/defend/websocket-connection/quick-start-and-best-practices.md)
* [Error Handling](/u/defend/websocket-connection/error-handling.md)
* [Authentication Guide](/u/defend/integration-guide/authentication.md)


---

# 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://docs.lsports.eu/u/defend/websocket-connection/code-examples.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.
