Debian Codegraph @

_examples/single_connection/readme.md

raw
1 This example demonstrates how to keep single connection from the same user globally over all Centrifuge nodes.
2
3 As soon as user connects we subscribe it to a personal channel with presence enabled. Then inside `OnConnect` handler we check whether user has more than 1 connection inside personal channel at the moment. If yes – we disconnect other user connections (except current one) from a server.
4
5 We also could disconnect all other user connections without using channel presence at all, but this results in more unnecessary disconnect messages travelling around Centrifuge nodes.
6
7 To start example run the following command from example directory:
8
9 ```
10 go run main.go
11 ```
12
13 Then go to http://localhost:8000 to see it in action. Then open another browser tab – as soon as the new connection establishes the previous one will be closed.