You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+40-6Lines changed: 40 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -227,16 +227,50 @@ fn main() -> None:
227
227
228
228
Pure Mojo-based client is available by default. This client is also used internally for testing the server.
229
229
230
-
## Switching between pure Mojo and Python implementations
231
-
232
-
By default, Lightbug uses the pure Mojo implementation for networking. To use Python's `socket` library instead, just import the `PythonServer` instead of the `Server` with the following line:
230
+
### UDP Support
231
+
To get started with UDP, just use the `listen_udp` and `dial_udp` functions, along with `write_to` and `read_from` methods, like below.
233
232
233
+
On the client:
234
234
```mojo
235
-
from lightbug_http.python.server import PythonServer
235
+
from lightbug_http.connection import dial_udp
236
+
from lightbug_http.address import UDPAddr
237
+
from utils import StringSlice
238
+
239
+
alias test_string = "Hello, lightbug!"
240
+
241
+
fn main() raises:
242
+
print("Dialing UDP server...")
243
+
alias host = "127.0.0.1"
244
+
alias port = 12000
245
+
var udp = dial_udp(host, port)
246
+
247
+
print("Sending " + str(len(test_string)) + " messages to the server...")
You can then use all the regular server commands in the same way as with the default server.
239
-
Note: as of September, 2024, `PythonServer` and `PythonClient` throw a compilation error when starting. There's an open [issue](https://github.com/saviorand/lightbug_http/issues/41) to fix this - contributions welcome!
260
+
On the server:
261
+
```mojo
262
+
fn main() raises:
263
+
var listener = listen_udp("127.0.0.1", 12000)
264
+
265
+
while True:
266
+
response, host, port = listener.read_from(16)
267
+
var message = StringSlice(unsafe_from_utf8=response)
0 commit comments