repodnet 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- repodnet-0.1.0/.github/workflows/ci.yml +62 -0
- repodnet-0.1.0/.gitignore +14 -0
- repodnet-0.1.0/.python-version +1 -0
- repodnet-0.1.0/COPYING +165 -0
- repodnet-0.1.0/PKG-INFO +202 -0
- repodnet-0.1.0/README.md +174 -0
- repodnet-0.1.0/docs/DOCS.md +767 -0
- repodnet-0.1.0/examples/chat_client.py +93 -0
- repodnet-0.1.0/examples/chat_server.py +98 -0
- repodnet-0.1.0/examples/lag_time_client.py +67 -0
- repodnet-0.1.0/examples/lag_time_server.py +58 -0
- repodnet-0.1.0/examples/whiteboard_client.py +209 -0
- repodnet-0.1.0/examples/whiteboard_server.py +110 -0
- repodnet-0.1.0/pyproject.toml +68 -0
- repodnet-0.1.0/repod/__init__.py +62 -0
- repodnet-0.1.0/repod/channel.py +214 -0
- repodnet-0.1.0/repod/client.py +276 -0
- repodnet-0.1.0/repod/constants.py +25 -0
- repodnet-0.1.0/repod/protocol.py +124 -0
- repodnet-0.1.0/repod/py.typed +0 -0
- repodnet-0.1.0/repod/server.py +217 -0
- repodnet-0.1.0/requirements.txt +1 -0
- repodnet-0.1.0/tests/__init__.py +0 -0
- repodnet-0.1.0/tests/test_constants.py +36 -0
- repodnet-0.1.0/tests/test_integration.py +187 -0
- repodnet-0.1.0/tests/test_protocol.py +163 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
lint:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
|
|
15
|
+
- name: Install uv
|
|
16
|
+
uses: astral-sh/setup-uv@v6
|
|
17
|
+
|
|
18
|
+
- name: Set up Python
|
|
19
|
+
run: uv python install 3.12
|
|
20
|
+
|
|
21
|
+
- name: Install dependencies
|
|
22
|
+
run: uv sync --group dev
|
|
23
|
+
|
|
24
|
+
- name: Ruff lint
|
|
25
|
+
run: uv run ruff check .
|
|
26
|
+
|
|
27
|
+
- name: Ruff format
|
|
28
|
+
run: uv run ruff format --check .
|
|
29
|
+
|
|
30
|
+
typecheck:
|
|
31
|
+
runs-on: ubuntu-latest
|
|
32
|
+
steps:
|
|
33
|
+
- uses: actions/checkout@v4
|
|
34
|
+
|
|
35
|
+
- name: Install uv
|
|
36
|
+
uses: astral-sh/setup-uv@v6
|
|
37
|
+
|
|
38
|
+
- name: Set up Python
|
|
39
|
+
run: uv python install 3.12
|
|
40
|
+
|
|
41
|
+
- name: Install dependencies
|
|
42
|
+
run: uv sync --group dev
|
|
43
|
+
|
|
44
|
+
- name: ty check
|
|
45
|
+
run: uv run ty check
|
|
46
|
+
|
|
47
|
+
test:
|
|
48
|
+
runs-on: ubuntu-latest
|
|
49
|
+
steps:
|
|
50
|
+
- uses: actions/checkout@v4
|
|
51
|
+
|
|
52
|
+
- name: Install uv
|
|
53
|
+
uses: astral-sh/setup-uv@v6
|
|
54
|
+
|
|
55
|
+
- name: Set up Python
|
|
56
|
+
run: uv python install 3.12
|
|
57
|
+
|
|
58
|
+
- name: Install dependencies
|
|
59
|
+
run: uv sync --group dev
|
|
60
|
+
|
|
61
|
+
- name: Run tests
|
|
62
|
+
run: uv run pytest tests/ -v
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.12
|
repodnet-0.1.0/COPYING
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version
|
|
113
|
+
of the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|
repodnet-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: repodnet
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Modern async networking library for multiplayer games
|
|
5
|
+
Project-URL: Homepage, https://github.com/Walkercito/repod
|
|
6
|
+
Project-URL: Repository, https://github.com/Walkercito/repod
|
|
7
|
+
Project-URL: Documentation, https://github.com/Walkercito/repod/blob/main/docs/DOCS.md
|
|
8
|
+
Project-URL: Issues, https://github.com/Walkercito/repod/issues
|
|
9
|
+
Author-email: Walkercito <walekrcitoliver@gmail.com>
|
|
10
|
+
License-Expression: LGPL-3.0-or-later
|
|
11
|
+
License-File: COPYING
|
|
12
|
+
Keywords: async,gamedev,msgpack,multiplayer,networking
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Games/Entertainment
|
|
21
|
+
Classifier: Topic :: Internet
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Classifier: Topic :: System :: Networking
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.12
|
|
26
|
+
Requires-Dist: msgpack>=1.0.0
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# repod -- multiplayer networking library for Python games
|
|
30
|
+
|
|
31
|
+
[](https://www.python.org/)
|
|
32
|
+
[](https://www.gnu.org/licenses/lgpl-3.0)
|
|
33
|
+
[](https://github.com/astral-sh/ruff)
|
|
34
|
+
[](https://msgpack.org/)
|
|
35
|
+
[](https://docs.python.org/3/library/asyncio.html)
|
|
36
|
+
|
|
37
|
+
repod is a networking library designed to make it easy to write multiplayer games in Python. It uses `asyncio` and `msgpack` to asynchronously serialize network events and arbitrary data structures, and delivers them to your high-level classes through simple callback methods.
|
|
38
|
+
|
|
39
|
+
It is a modernized fork of [PodSixNet](https://github.com/chr15m/PodSixNet). Same ideas -- channels, action-based message dispatch, synchronous pump loops -- but rebuilt from scratch for Python 3.12+ with async I/O, binary msgpack serialization, and full type annotations. PodSixNet was built on `asyncore`, which was removed in Python 3.12; repod is the drop-in replacement.
|
|
40
|
+
|
|
41
|
+
Each class within your game client which wants to receive network events subclasses `ConnectionListener` and implements `Network_*` methods to catch specific events from the server. You don't have to wait for buffers to fill, or check sockets for waiting data or anything like that -- just call `client.pump()` once per game loop and the library handles everything else, passing off events to your listener. Sending data back to the server is just as easy with `client.send(mydata)`. On the server side, events are propagated to `Network_*` callbacks on your `Channel` subclass, and data is sent back to clients with `channel.send(mydata)`.
|
|
42
|
+
|
|
43
|
+
## Install
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install repod
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Or with [uv](https://docs.astral.sh/uv/):
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
uv add repod
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Examples
|
|
56
|
+
|
|
57
|
+
Chat example:
|
|
58
|
+
|
|
59
|
+
- `python examples/chat_server.py`
|
|
60
|
+
- and a couple of instances of `python examples/chat_client.py`
|
|
61
|
+
|
|
62
|
+
Whiteboard example (requires pygame-ce):
|
|
63
|
+
|
|
64
|
+
- `python examples/whiteboard_server.py`
|
|
65
|
+
- and a couple of instances of `python examples/whiteboard_client.py`
|
|
66
|
+
|
|
67
|
+
LagTime example (measures round-trip time from server to client):
|
|
68
|
+
|
|
69
|
+
- `python examples/lag_time_server.py`
|
|
70
|
+
- and a couple of instances of `python examples/lag_time_client.py`
|
|
71
|
+
|
|
72
|
+
## Quick start -- Server
|
|
73
|
+
|
|
74
|
+
You need to subclass two classes to make your own server. Each time a client connects, a new `Channel` instance is created, so you subclass `Channel` to make your server-side representation of a client:
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from repod import Channel
|
|
78
|
+
|
|
79
|
+
class ClientChannel(Channel):
|
|
80
|
+
|
|
81
|
+
def network_received(self, data: dict) -> None:
|
|
82
|
+
print(data)
|
|
83
|
+
|
|
84
|
+
def Network_myaction(self, data: dict) -> None:
|
|
85
|
+
print("myaction:", data)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Whenever the client sends data, the `network_received()` fallback is called if no specific handler exists. The method `Network_myaction()` is only called if your data has an `"action"` key with a value of `"myaction"`. In other words, if the data looks like:
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
{"action": "myaction", "blah": 123, ...}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Next, subclass `Server`:
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from repod import Server
|
|
98
|
+
|
|
99
|
+
class MyServer(Server):
|
|
100
|
+
channel_class = ClientChannel
|
|
101
|
+
|
|
102
|
+
def on_connect(self, channel, addr):
|
|
103
|
+
print("new connection:", channel)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Set `channel_class` to the Channel subclass you created above. The `on_connect()` method is called whenever a new client connects.
|
|
107
|
+
|
|
108
|
+
To run the server, call `launch()`:
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
MyServer(host="0.0.0.0", port=5071).launch()
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
That's it. One line. `launch()` handles the event loop internally and catches `Ctrl+C` for clean shutdown.
|
|
115
|
+
|
|
116
|
+
When you want to send data to a specific client, use the `send` method on the Channel:
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
channel.send({"action": "hello", "message": "hello client!"})
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Quick start -- Client
|
|
123
|
+
|
|
124
|
+
To connect to your server, subclass `ConnectionListener`:
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
import time
|
|
128
|
+
from repod import ConnectionListener
|
|
129
|
+
|
|
130
|
+
class MyClient(ConnectionListener):
|
|
131
|
+
|
|
132
|
+
def Network_connected(self, data: dict) -> None:
|
|
133
|
+
print("connected to the server")
|
|
134
|
+
|
|
135
|
+
def Network_error(self, data: dict) -> None:
|
|
136
|
+
print("error:", data["error"])
|
|
137
|
+
|
|
138
|
+
def Network_disconnected(self, data: dict) -> None:
|
|
139
|
+
print("disconnected from the server")
|
|
140
|
+
|
|
141
|
+
def Network_myaction(self, data: dict) -> None:
|
|
142
|
+
print("myaction:", data)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Network events are received by `Network_*` callback methods. Replace `*` with the value of the `"action"` key you want to catch. The `connected`, `disconnected`, and `error` events are sent automatically by repod.
|
|
146
|
+
|
|
147
|
+
Connect and pump:
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
client = MyClient()
|
|
151
|
+
client.connect("localhost", 5071)
|
|
152
|
+
|
|
153
|
+
while True:
|
|
154
|
+
client.pump()
|
|
155
|
+
time.sleep(0.01)
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Call `pump()` once per game loop and repod handles everything -- reading from the socket, deserializing, and dispatching to your `Network_*` methods. Sending data to the server:
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
client.send({"action": "myaction", "blah": 123, "things": [3, 4, 3, 4, 7]})
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
This works with any game framework that has a main loop: pygame, raylib, arcade, pyglet, etc. Just drop `pump()` into the loop.
|
|
165
|
+
|
|
166
|
+
## Documentation
|
|
167
|
+
|
|
168
|
+
Full tutorial and API reference: **[docs/DOCS.md](docs/DOCS.md)**
|
|
169
|
+
|
|
170
|
+
## Why not PodSixNet?
|
|
171
|
+
|
|
172
|
+
PodSixNet was great for its time, but:
|
|
173
|
+
|
|
174
|
+
- It's built on `asyncore`, which was **removed in Python 3.12**
|
|
175
|
+
- It uses `rencode` / custom delimiter-based framing (`\0---\0`), which is fragile with binary data
|
|
176
|
+
- It has no type annotations, no modern tooling support
|
|
177
|
+
- It is no longer maintained ([chr15m/PodSixNet#46](https://github.com/chr15m/PodSixNet/issues/46))
|
|
178
|
+
|
|
179
|
+
repod keeps the same simple API philosophy but replaces the internals:
|
|
180
|
+
|
|
181
|
+
- **asyncio** instead of asyncore
|
|
182
|
+
- **msgpack** with length-prefix framing instead of rencode with delimiter framing
|
|
183
|
+
- **Full type annotations** with PEP 695 generics (optional)
|
|
184
|
+
- **Python 3.12+** only -- no compatibility shims
|
|
185
|
+
|
|
186
|
+
## Development
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
uv sync --group dev
|
|
190
|
+
uv run ruff check .
|
|
191
|
+
uv run ruff format --check .
|
|
192
|
+
uv run ty check
|
|
193
|
+
uv run pytest tests/ -v
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## License
|
|
197
|
+
|
|
198
|
+
Copyright Walker Gonzales, 2025.
|
|
199
|
+
|
|
200
|
+
repod is licensed under the terms of the **LGPL v3.0** or later. See the [COPYING](COPYING) file for details.
|
|
201
|
+
|
|
202
|
+
This is the same license as [PodSixNet](https://github.com/chr15m/PodSixNet), from which repod is forked. In short: you can use repod in any project (commercial or otherwise), but if you modify the repod library code itself, you must make the modified source available.
|
repodnet-0.1.0/README.md
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# repod -- multiplayer networking library for Python games
|
|
2
|
+
|
|
3
|
+
[](https://www.python.org/)
|
|
4
|
+
[](https://www.gnu.org/licenses/lgpl-3.0)
|
|
5
|
+
[](https://github.com/astral-sh/ruff)
|
|
6
|
+
[](https://msgpack.org/)
|
|
7
|
+
[](https://docs.python.org/3/library/asyncio.html)
|
|
8
|
+
|
|
9
|
+
repod is a networking library designed to make it easy to write multiplayer games in Python. It uses `asyncio` and `msgpack` to asynchronously serialize network events and arbitrary data structures, and delivers them to your high-level classes through simple callback methods.
|
|
10
|
+
|
|
11
|
+
It is a modernized fork of [PodSixNet](https://github.com/chr15m/PodSixNet). Same ideas -- channels, action-based message dispatch, synchronous pump loops -- but rebuilt from scratch for Python 3.12+ with async I/O, binary msgpack serialization, and full type annotations. PodSixNet was built on `asyncore`, which was removed in Python 3.12; repod is the drop-in replacement.
|
|
12
|
+
|
|
13
|
+
Each class within your game client which wants to receive network events subclasses `ConnectionListener` and implements `Network_*` methods to catch specific events from the server. You don't have to wait for buffers to fill, or check sockets for waiting data or anything like that -- just call `client.pump()` once per game loop and the library handles everything else, passing off events to your listener. Sending data back to the server is just as easy with `client.send(mydata)`. On the server side, events are propagated to `Network_*` callbacks on your `Channel` subclass, and data is sent back to clients with `channel.send(mydata)`.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install repod
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Or with [uv](https://docs.astral.sh/uv/):
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
uv add repod
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Examples
|
|
28
|
+
|
|
29
|
+
Chat example:
|
|
30
|
+
|
|
31
|
+
- `python examples/chat_server.py`
|
|
32
|
+
- and a couple of instances of `python examples/chat_client.py`
|
|
33
|
+
|
|
34
|
+
Whiteboard example (requires pygame-ce):
|
|
35
|
+
|
|
36
|
+
- `python examples/whiteboard_server.py`
|
|
37
|
+
- and a couple of instances of `python examples/whiteboard_client.py`
|
|
38
|
+
|
|
39
|
+
LagTime example (measures round-trip time from server to client):
|
|
40
|
+
|
|
41
|
+
- `python examples/lag_time_server.py`
|
|
42
|
+
- and a couple of instances of `python examples/lag_time_client.py`
|
|
43
|
+
|
|
44
|
+
## Quick start -- Server
|
|
45
|
+
|
|
46
|
+
You need to subclass two classes to make your own server. Each time a client connects, a new `Channel` instance is created, so you subclass `Channel` to make your server-side representation of a client:
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from repod import Channel
|
|
50
|
+
|
|
51
|
+
class ClientChannel(Channel):
|
|
52
|
+
|
|
53
|
+
def network_received(self, data: dict) -> None:
|
|
54
|
+
print(data)
|
|
55
|
+
|
|
56
|
+
def Network_myaction(self, data: dict) -> None:
|
|
57
|
+
print("myaction:", data)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Whenever the client sends data, the `network_received()` fallback is called if no specific handler exists. The method `Network_myaction()` is only called if your data has an `"action"` key with a value of `"myaction"`. In other words, if the data looks like:
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
{"action": "myaction", "blah": 123, ...}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Next, subclass `Server`:
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from repod import Server
|
|
70
|
+
|
|
71
|
+
class MyServer(Server):
|
|
72
|
+
channel_class = ClientChannel
|
|
73
|
+
|
|
74
|
+
def on_connect(self, channel, addr):
|
|
75
|
+
print("new connection:", channel)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Set `channel_class` to the Channel subclass you created above. The `on_connect()` method is called whenever a new client connects.
|
|
79
|
+
|
|
80
|
+
To run the server, call `launch()`:
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
MyServer(host="0.0.0.0", port=5071).launch()
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
That's it. One line. `launch()` handles the event loop internally and catches `Ctrl+C` for clean shutdown.
|
|
87
|
+
|
|
88
|
+
When you want to send data to a specific client, use the `send` method on the Channel:
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
channel.send({"action": "hello", "message": "hello client!"})
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Quick start -- Client
|
|
95
|
+
|
|
96
|
+
To connect to your server, subclass `ConnectionListener`:
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
import time
|
|
100
|
+
from repod import ConnectionListener
|
|
101
|
+
|
|
102
|
+
class MyClient(ConnectionListener):
|
|
103
|
+
|
|
104
|
+
def Network_connected(self, data: dict) -> None:
|
|
105
|
+
print("connected to the server")
|
|
106
|
+
|
|
107
|
+
def Network_error(self, data: dict) -> None:
|
|
108
|
+
print("error:", data["error"])
|
|
109
|
+
|
|
110
|
+
def Network_disconnected(self, data: dict) -> None:
|
|
111
|
+
print("disconnected from the server")
|
|
112
|
+
|
|
113
|
+
def Network_myaction(self, data: dict) -> None:
|
|
114
|
+
print("myaction:", data)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Network events are received by `Network_*` callback methods. Replace `*` with the value of the `"action"` key you want to catch. The `connected`, `disconnected`, and `error` events are sent automatically by repod.
|
|
118
|
+
|
|
119
|
+
Connect and pump:
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
client = MyClient()
|
|
123
|
+
client.connect("localhost", 5071)
|
|
124
|
+
|
|
125
|
+
while True:
|
|
126
|
+
client.pump()
|
|
127
|
+
time.sleep(0.01)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Call `pump()` once per game loop and repod handles everything -- reading from the socket, deserializing, and dispatching to your `Network_*` methods. Sending data to the server:
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
client.send({"action": "myaction", "blah": 123, "things": [3, 4, 3, 4, 7]})
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
This works with any game framework that has a main loop: pygame, raylib, arcade, pyglet, etc. Just drop `pump()` into the loop.
|
|
137
|
+
|
|
138
|
+
## Documentation
|
|
139
|
+
|
|
140
|
+
Full tutorial and API reference: **[docs/DOCS.md](docs/DOCS.md)**
|
|
141
|
+
|
|
142
|
+
## Why not PodSixNet?
|
|
143
|
+
|
|
144
|
+
PodSixNet was great for its time, but:
|
|
145
|
+
|
|
146
|
+
- It's built on `asyncore`, which was **removed in Python 3.12**
|
|
147
|
+
- It uses `rencode` / custom delimiter-based framing (`\0---\0`), which is fragile with binary data
|
|
148
|
+
- It has no type annotations, no modern tooling support
|
|
149
|
+
- It is no longer maintained ([chr15m/PodSixNet#46](https://github.com/chr15m/PodSixNet/issues/46))
|
|
150
|
+
|
|
151
|
+
repod keeps the same simple API philosophy but replaces the internals:
|
|
152
|
+
|
|
153
|
+
- **asyncio** instead of asyncore
|
|
154
|
+
- **msgpack** with length-prefix framing instead of rencode with delimiter framing
|
|
155
|
+
- **Full type annotations** with PEP 695 generics (optional)
|
|
156
|
+
- **Python 3.12+** only -- no compatibility shims
|
|
157
|
+
|
|
158
|
+
## Development
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
uv sync --group dev
|
|
162
|
+
uv run ruff check .
|
|
163
|
+
uv run ruff format --check .
|
|
164
|
+
uv run ty check
|
|
165
|
+
uv run pytest tests/ -v
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## License
|
|
169
|
+
|
|
170
|
+
Copyright Walker Gonzales, 2025.
|
|
171
|
+
|
|
172
|
+
repod is licensed under the terms of the **LGPL v3.0** or later. See the [COPYING](COPYING) file for details.
|
|
173
|
+
|
|
174
|
+
This is the same license as [PodSixNet](https://github.com/chr15m/PodSixNet), from which repod is forked. In short: you can use repod in any project (commercial or otherwise), but if you modify the repod library code itself, you must make the modified source available.
|