From c69fa66f609925a98acf8dc7f645b9b50ce3a8ba Mon Sep 17 00:00:00 2001 From: rodri Date: Sat, 11 Jun 2022 22:37:59 +0000 Subject: implemented a custom PDU/frame structure on top of UDP for game networking. --- musw.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'musw.c') diff --git a/musw.c b/musw.c index 70a8a4b..10ca01b 100644 --- a/musw.c +++ b/musw.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -219,12 +220,23 @@ threadnetsend(void *arg) uchar buf[1024]; int fd, n; ulong kdown; + Frame *frame; fd = *(int*)arg; + frame = emalloc(sizeof(Frame)+sizeof(kdown)); + frame->udp = nil; + frame->seq = 223; + frame->ack = 222; + frame->id = ntruerand(100); + frame->len = sizeof(kdown); for(;;){ kdown = recvul(kchan); - n = pack(buf, sizeof buf, "k", kdown); + frame->data[0] = kdown>>24; + frame->data[1] = kdown>>16; + frame->data[2] = kdown>>8; + frame->data[3] = kdown; + n = pack(buf, sizeof buf, "F", frame); if(write(fd, buf, n) != n) sysfatal("write: %r"); } -- cgit v1.2.3