-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[rnet] Simple and easy-to-use network module for raylib #753
Comments
Blocking till a packet arrives doesn't sound too useful, so I assume it will poll for new packets and return immediately? |
Probably shouldn't use something so low level as raw tcp/udp style interfaces. Should probably build raynet around something like https://github.com/SLikeSoft/SLikeNet or so instead as they have actually useful constructs for games. |
I think a |
One haircut later. // This call can fail on windows, it is rare but should be accounted for.
bool InitNetworkDevice(NetworkConfig config);
//Why is the hostid included here?
bool NetworkDisconnect(int hostId, int connectionId);
//This should return something, maybe not int but atleast a bool.
//But giving the user an option to track the sent bytes is useful
//Why is hostid included here?
//What is channelId supposed to be used for?
int NetworkSend(int hostId, int connectionId, int channelId, void *data, int length);
//Why is hostid included here?
//What is channelId supposed to be used for?
int NetworkReceive(int hostId, int connectionId, int channelId, void *data, int length); Other than that i can only suggest expanding it with some encoding functions etc. |
I'll make this a separate thing, focusing on UDP and implementing WebSockets seems sort of weird? Provided that the idea is to be able to make a GET and POST request this should not be impossible, however then we should sit down and focus on what part of the HTTP protocol, we would want since posts and gets can be very funcy if you let them. |
|
It itself is yes, hence why it should be entirely wrapped, it should not be exposed to the user of the library at all.
It's license allows baking it into a project so it's no longer an external dependency. |
Thanks to all of you for your answers! :) @a3f @Skabunkel yes, functions should return some state info. |
Ah, that makes sense. unsure how that would work in webasm but oh well, the joy of exploration. |
Android NDK sockets |
Why so low level? Some things like packet sequencing and relability would be nice (something like eg. ENet, look at packet flags), those things are hard to make for new programmers and would help them with networking. |
@zaknet I've been working on small network module for raylib - hence why this issue was opened, I plan to have a similar api to sfml/sdl_net for those who want to use platform agnostic socket calls. I've also got plans to include a, as you put it 'higher level' game api on top, the goal is to support basic replication, serialisation, callbacks, sequencing etc for those less familiar with networking |
With raylib having quite a minimalist api however, my roadmap for the module is very much subject to change. Within the week I'll likely post a spec, outline what features I intend to add and we can have a discussion about what belongs in an api call, and what we can provide as examples :) |
@Skabunkel Thank you very much for the links! I looks pretty good! Supporting WEB and ANDROID has been added to the list! |
By the way, @Syphonx, do you think we could have a functional version to be included on |
I plan to have barebones support for TCP/UDP, a low(er)-level socket api, serialisation helpers and some examples done in the next week or so @raysan5 |
Features like replication, data packet tags and more advanced features will likely be added on an 'as we go' basis |
An attempt to use any networking library that includes Windows headers already have these declarations. I'm surprised that you don't follow an appropriate naming conventions with a vendor-specific prefix, this is quite trivial thing in C. |
I used Raylib in NetDynamics if you're interested. I've added |
@nxrighthere Hey! Excuse me for this super-late response, I completely forget about this issue... About Personally I don't like prefixes (when I started raylib I came from C# world) but I agree it's the best option in C to avoid that kind of collisions... maybe in a future update of raylib... Congrats for the |
@raysan5 Thanks, I glad that you like it.
Well, it's not a problem for me I've just made a small script that renames everything. But, for example, people to whom I suggested Raylib in my community encountered the same problem, and they were really unhappy with that, so I think it would be better to solve this out of the box with the traditional approach. Thank you for your work anyway, it's a very helpful thing for fast prototyping. |
Just for reference, I found swrap library, looks very interesting! |
Such stuff is just a very basic UDP API, for multiplayer games, you will need a networking library with a mature protocol that carries at least these features:
This is only the tip of the iceberg, consider something that provides such feature-set out of the box. Godot is using ENet which is used in many modern games today such as League of Legends for example (they are using cryptography for payload on top). |
For inspiration: |
Hey guys! Is someone working on this? |
Hi @paezao! Not really, I did some review a while ago but it's not functional at this moment... My plan was simplifying the API and use UDP-only. |
Hey @raysan5, I asked you recently about enet. You told me that you're looking for single files with single headers. But do you actually like enet? I mean, if someone took the source code and put it all together in a single organized file+header, would you use it or does enet lack features that you want? |
A single-header fork is available here. It's used in several games in production. |
@nxrighthere Oh! Thank you very much for sharing! |
What a coincidence @nxrighthere , I recently starred your fork before posting here, I hope @raysan5 likes it. I want to use it for some Unity projects. |
Another great alternative: enet single-header fork: https://github.com/zpl-c/enet |
zpl-c/enet is the particular repo that I used in my multiplayer pong clone I wrote a couple of days ago. I have little to no background in C and managed to get it up and going fairly quickly which suggests it must be fairly easy to use.
Rough mapping of code snippets to proposed API below:
So a thin wrapper over ENet within the same single file seems viable, so long as your happy with the ENet license and whatever maintenance goes along with it. The only other convenience function that would be nice is some sort of transport-layer compression and encryption which should be possible before crafting the ENet packet. I started having a look at the existing rnet code and for a novice like me it looks like it would be a little easier to maintain/debug than ENet since it is much simpler. That said there would probably be more work in completing it than an ENet wrapper. Effort/maintenance/functionality tradeoff I guess. |
@bloodhaze13 thanks for the info! Current Lately I also keep an eye to another very promising library: https://github.com/nathhB/nbnet |
Hello, |
This issue has been open for too long, many alternatives have been proposed here and actually |
Mongoose Embedded web server seems to be a complete embedded and self contained web server written in C and shipped in a sigle C file (+header) I drop here this reference to keep track of it. |
Hello. I'm the author of nbnet. I discussed with Ray and started working on a potential rnet implementation (as a nbnet wrapper). You can follow the progress here for now. Take a look at rnet.h for a good overview of the API. |
@nathhB I'm reopening the issue for further discussion! |
@raysan5 I forked raylib: https://github.com/nathhB/raylib. This is where I will update rnet so you can look there when you want to review it. I'm gonna leave it as-is until it has been reviewed as I think it lays a good fundation to build upon. There are two files: rnet.h and rnet.c. |
After reviewing Other libraries used on raylib like Still, some |
As already mentioned several times by raylib community, a network module is a missing piece on raylib. Long ago I started drafting a possible network module API for raylib but due to lack of resources, project was stopped... I start this issue to list project specifications and references.
rnet
is a simple and easy-to-use network library. Some desired features:rnet.c
) but also usable as a standalone librarywinsock2.h
/socket.h
)rnet.h
+rnet.c
Just as a quick reference, the following APIs have been analyzed:
I'm not an expert on network programming, actually last time I remember doing some sockets code was on University... but here it is basic raynet API proposal (probably very improvable):
Just keep in mind this API is a very rough proposal...
EDIT: Added to list desired support for WEB and ANDROID.
The text was updated successfully, but these errors were encountered: