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
+53-26Lines changed: 53 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -29,11 +29,10 @@ Lightbug is a simple and sweet HTTP framework for Mojo that builds on best pract
29
29
This is not production ready yet. We're aiming to keep up with new developments in Mojo, but it might take some time to get to a point when this is safe to use in real-world applications.
30
30
31
31
Lightbug currently has the following features:
32
-
-[x] Pure Mojo networking! No dependencies on Python by default
33
-
-[x] TCP-based server and client implementation
34
-
-[x] Assign your own custom handler to a route
35
-
-[x] Craft HTTP requests and responses with built-in primitives
36
-
-[x] Everything is fully typed, with no `def` functions used
32
+
-[x] Pure Mojo! No Python dependencies. Everything is fully typed, with no `def` functions used
33
+
-[x] HTTP Server and Client implementations
34
+
-[x] TCP and UDP support
35
+
-[x] Cookie support
37
36
38
37
### Check Out These Mojo Libraries:
39
38
@@ -123,12 +122,12 @@ Once you have a Mojo project set up locally,
"Is connection set to connection-close? ", response.connection_close()
@@ -229,16 +224,50 @@ fn main() -> None:
229
224
230
225
Pure Mojo-based client is available by default. This client is also used internally for testing the server.
231
226
232
-
## Switching between pure Mojo and Python implementations
233
-
234
-
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:
227
+
### UDP Support
228
+
To get started with UDP, just use the `listen_udp` and `dial_udp` functions, along with `write_to` and `read_from` methods, like below.
235
229
230
+
On the client:
236
231
```mojo
237
-
from lightbug_http.python.server import PythonServer
232
+
from lightbug_http.connection import dial_udp
233
+
from lightbug_http.address import UDPAddr
234
+
from utils import StringSlice
235
+
236
+
alias test_string = "Hello, lightbug!"
237
+
238
+
fn main() raises:
239
+
print("Dialing UDP server...")
240
+
alias host = "127.0.0.1"
241
+
alias port = 12000
242
+
var udp = dial_udp(host, port)
243
+
244
+
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.
241
-
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!
257
+
On the server:
258
+
```mojo
259
+
fn main() raises:
260
+
var listener = listen_udp("127.0.0.1", 12000)
261
+
262
+
while True:
263
+
response, host, port = listener.read_from(16)
264
+
var message = StringSlice(unsafe_from_utf8=response)
0 commit comments