--- /dev/null
+# Onyx-Net
+
+Stable and reliable networking protocol on top of UDP for
+games and applications. It is based off of ENet, but is not compatible
+in the slightest with it.
+
+A single server is connected to by multiple clients using a UDP Socket
+each. On each socket, multiple channels are used. Each channel supports:
+ - Sequencing
+ - Reliable transmissions
+ - Commands (control codes)
+
+These are supported independent of the other channels. This enable the
+programmer to use sequencial packets for data that needs to arrive in
+order, and unsequencial / unreliable packets for things like movement
+updates.
+
+This protocol will also support larger transmissions, though for
+practically, assume that anything over 1MB in size should probably be
+transferred in a different way, or chunked up by the application layer.
+
+
+Currently, these features are not supported:
+[ ] Bundle acknowledgement messages together.
+
+[ ] Packets are not necessarily sequenced. A dropped packet followed
+ by a successful packet with be out of order.
+
+[x] Framemented reliable data.
+++ /dev/null
-# Onyx-Net
-
-Stable and reliable networking protocol on top of UDP for
-games and applications. It is based off of ENet, but is not compatible
-in the slightest with it.
-
-A single server is connected to by multiple clients using a UDP Socket
-each. On each socket, multiple channels are used. Each channel supports:
- - Sequencing
- - Reliable transmissions
- - Commands (control codes)
-These are supported independent of the other channels. This enable the
-programmer to use sequencial packets for data that needs to arrive in
-order, and unsequencial / unreliable packets for things like movement
-updates.
-
-This protocol will also support larger transmissions, though for
-practically, assume that anything over 1MB in size should probably be
-transferred in a different way, or chunked up by the application layer.
-
-
-
-Each packet is at most 1400 bytes in size.
-
-0 2 4 6 8 ...
-| peerID | sentTime | checksum | channelID | commandID | data
- OPTIONAL OPTIONAL
-
-
-Currently, these features are not supported:
- [ ] Packets are not necessarily sequenced. A dropped packet followed
- by a successful packet with be out of order.
-
- [x] Framemented reliable data.
\ No newline at end of file
--- /dev/null
+#load "core/std"
+#load "src/module"
+
+use package core
+onyx_net :: package onyx_net
+
+octets_to_addr :: (a, b, c, d: u8) -> u32 {
+ return (cast(u32) a << 24) |
+ (cast(u32) b << 16) |
+ (cast(u32) c << 8) |
+ (cast(u32) d << 0);
+}
+
+main :: (args) => {
+ //
+ // 'null' signifies that this host should not bind a socket
+ // to a port. Only 1 peer is needed, as this is only connecting
+ // to one server.
+ host: ^onyx_net.Host;
+ if host', err := onyx_net.host_create(null, 1); err != .None {
+ println(err);
+ }
+
+ addr: net.Socket_Address;
+ addr.addr = octets_to_addr(127, 0, 0, 1);
+ addr.port = 8080;
+ peer := onyx_net.host_connect(host, ^addr, 2);
+
+ input_thread: thread.Thread;
+ td_type :: struct { peer: ^onyx_net.Peer; }
+ td := td_type.{ peer };
+
+ thread.spawn(^input_thread, ^td, (data) => {
+ peer := data.peer;
+ input_reader := io.reader_make(^stdin);
+
+ while true {
+ line := io.read_line(^input_reader) |> string.strip_whitespace();
+
+ switch line {
+ case "disconnect" {
+ println("Disconnecting");
+ onyx_net.peer_send_disconnect(peer);
+ onyx_net.peer_flush_outgoing_commands(peer);
+ onyx_net.peer_disconnect(peer);
+ break;
+ }
+
+ case "send" {
+ packet := new(onyx_net.Packet);
+ packet.flags |= .Reliable;
+ packet.data = "What's Up?";
+ println("Sending what's up...");
+
+ onyx_net.peer_send(peer, 0, packet);
+ }
+ }
+ }
+ });
+
+ while true {
+ for host->get_events(timeout=100) {
+ // printf("{*}\n", it);
+
+ if it.type == .Connection {
+ println("Successfully connected to server!");
+ }
+
+ if it.type == .Disconnection {
+ println("Lost connection to server.");
+ break break;
+ }
+
+ if it.type == .Message {
+ print("Server says: ");
+ print(it.data);
+ print("\n");
+ }
+
+ // if it.type == .Message {
+ // packet := new(onyx_net.Packet);
+ // packet.flags |= .Reliable;
+ // packet.data = "HELLO";
+
+ // onyx_net.peer_send(it.peer, 0, packet);
+ // }
+ }
+
+ // if random.between(0, 3) == 0 {
+ // packet := new(onyx_net.Packet);
+ // packet.flags |= .Reliable;
+ // packet.data = "What's Up?";
+ // println("Sending what's up...");
+
+ // onyx_net.peer_send(peer, 0, packet);
+ // }
+
+ // if random.between(0, 100) == 4 {
+ // println("Disconnecting");
+ // onyx_net.peer_send_disconnect(peer);
+ // onyx_net.peer_flush_outgoing_commands(peer);
+ // onyx_net.peer_disconnect(peer);
+ // break;
+ // }
+ }
+}
--- /dev/null
+#load "core/std"
+#load "src/module"
+
+use package core
+onyx_net :: package onyx_net
+
+
+main :: (args) => {
+ addr: net.Socket_Address;
+ addr.port = 8080;
+
+ server, err := onyx_net.host_create(^addr, 32);
+ if err != .None {
+ println(err);
+ return;
+ }
+
+ while true {
+ for server->get_events(timeout = 2000) {
+ // printf("{*}\n", it);
+
+ if it.type == .Connection {
+ printf("New connection from: {}\n", it.peer.addr);
+ packet := new(onyx_net.Packet);
+ packet.flags |= .Reliable;
+ packet.data = "Welcome!!!";
+
+ onyx_net.host_broadcast(server, 0, packet);
+ }
+
+ if it.type == .Disconnection {
+ printf("Disconnection: {}\n", it.peer.addr);
+ }
+
+ if it.type == .Message {
+ if it.data == "What's Up?" {
+ packet := new(onyx_net.Packet);
+ packet.flags |= .Reliable;
+ packet.data = #file_contents "src/host.onyx";
+
+ onyx_net.peer_send(it.peer, 0, packet);
+ }
+ }
+ }
+ }
+}
host.current_time = ~~ (os.time() & cast(u64) 0xFFFFFFFF);
for^ peer: host.peers {
+ memory.set(peer, 0, sizeof typeof *peer);
peer.host = host;
peer.state = .Disconnected;
peer.channels = .{ null, 0 };
Peer :: struct {
host: ^Host;
- addr: net.Socket_Address;
state: Peer_State;
+ addr: net.Socket_Address;
channels: [] Channel;
+++ /dev/null
-#load "core/std"
-#load "src/module"
-
-use package core
-onyx_net :: package onyx_net
-
-octets_to_addr :: (a, b, c, d: u8) -> u32 {
- return (cast(u32) a << 24) |
- (cast(u32) b << 16) |
- (cast(u32) c << 8) |
- (cast(u32) d << 0);
-}
-
-main :: (args) => {
- //
- // 'null' signifies that this host should not bind a socket
- // to a port. Only 1 peer is needed, as this is only connecting
- // to one server.
- host: ^onyx_net.Host;
- if host', err := onyx_net.host_create(null, 1); err != .None {
- println(err);
- }
-
- addr: net.Socket_Address;
- addr.addr = octets_to_addr(127, 0, 0, 1);
- addr.port = 8080;
- peer := onyx_net.host_connect(host, ^addr, 2);
-
- input_thread: thread.Thread;
- td_type :: struct { peer: ^onyx_net.Peer; }
- td := td_type.{ peer };
-
- thread.spawn(^input_thread, ^td, (data) => {
- peer := data.peer;
- input_reader := io.reader_make(^stdin);
-
- while true {
- line := io.read_line(^input_reader) |> string.strip_whitespace();
-
- switch line {
- case "disconnect" {
- println("Disconnecting");
- onyx_net.peer_send_disconnect(peer);
- onyx_net.peer_flush_outgoing_commands(peer);
- onyx_net.peer_disconnect(peer);
- break;
- }
-
- case "send" {
- packet := new(onyx_net.Packet);
- packet.flags |= .Reliable;
- packet.data = "What's Up?";
- println("Sending what's up...");
-
- onyx_net.peer_send(peer, 0, packet);
- }
- }
- }
- });
-
- while true {
- for host->get_events(timeout=100) {
- // printf("{*}\n", it);
-
- if it.type == .Connection {
- println("Successfully connected to server!");
- }
-
- if it.type == .Disconnection {
- println("Lost connection to server.");
- break break;
- }
-
- if it.type == .Message {
- print("Server says: ");
- print(it.data);
- print("\n");
- }
-
- // if it.type == .Message {
- // packet := new(onyx_net.Packet);
- // packet.flags |= .Reliable;
- // packet.data = "HELLO";
-
- // onyx_net.peer_send(it.peer, 0, packet);
- // }
- }
-
- // if random.between(0, 3) == 0 {
- // packet := new(onyx_net.Packet);
- // packet.flags |= .Reliable;
- // packet.data = "What's Up?";
- // println("Sending what's up...");
-
- // onyx_net.peer_send(peer, 0, packet);
- // }
-
- // if random.between(0, 100) == 4 {
- // println("Disconnecting");
- // onyx_net.peer_send_disconnect(peer);
- // onyx_net.peer_flush_outgoing_commands(peer);
- // onyx_net.peer_disconnect(peer);
- // break;
- // }
- }
-}
+++ /dev/null
-#load "core/std"
-#load "src/module"
-
-use package core
-onyx_net :: package onyx_net
-
-
-main :: (args) => {
- addr: net.Socket_Address;
- addr.port = 8080;
-
- server, err := onyx_net.host_create(^addr, 32);
- if err != .None {
- println(err);
- return;
- }
-
- while true {
- for server->get_events(timeout = 2000) {
- // printf("{*}\n", it);
-
- if it.type == .Connection {
- printf("New connection from: {}\n", it.peer.addr);
- packet := new(onyx_net.Packet);
- packet.flags |= .Reliable;
- packet.data = "Welcome!!!";
-
- onyx_net.host_broadcast(server, 0, packet);
- }
-
- if it.type == .Disconnection {
- printf("Disconnection: {}\n", it.peer.addr);
- }
-
- if it.type == .Message {
- if it.data == "What's Up?" {
- packet := new(onyx_net.Packet);
- packet.flags |= .Reliable;
- packet.data = #file_contents "src/host.onyx";
-
- onyx_net.peer_send(it.peer, 0, packet);
- }
- }
- }
- }
-}