RakNet Wrapper 0.5 Released

Blitz3D Forums/Blitz3D Userlibs/RakNet Wrapper 0.5 Released

KuRiX(Posted 2005) [#1]

Well, The Wrapper is growing good!

It Includes:
- All Server Functions
- All Client Functions
- All BitStream Functions
- All Statistics Functions

Decls file is not commented, because it is generated automatically using Flex for Windows.

RakNet Free Wrapper Download:

Buy the Source Code of the Wrapper (2.483) from:
Price: 20

If you find useful this library, and you want to donate, please visit:


0.5 (26-08-05): Initial Release
0.6 (27-08-05): Added Index Player and better test.bb
0.65 (28-08-05): Added Kick player and manual kick in test.bb
0.75 (07-10-05): Updated to the 2.4 official version.
0.76 (5-12-05): Updated to the 2.415 official version.

RakNet Official Web:

The .bb test included is too basic, please someone makes a better one!

And the best thing: IT IS FREE! (For commercial you only need permission)

Cheers, KuRi.

Alienforce(Posted 2005) [#2]

Nice work KuRiX.

And thanks..


KuRiX(Posted 2005) [#3]
I think that Surreal won't update BlitzPlay anymore, and this library offer ALL the functions that BlitzPlay has and much much more!.

So let's test it to make it work perfectly!

I suggest you to download the free version of Raknet that comes with samples in C++ that are very easily adapted to my wrapper.

I am now trying to connect and disconnect players, use passwords, update positions, etc... and is working perfectly!

Wayne(Posted 2005) [#4]
Hi Kurix,
Looks like a great looking api, so I'm going to download and check it out. thanks

KuRiX(Posted 2005) [#5]
I am going to change my blitzplay network code to this, to see if it is good. This is why i have made the wrapper. But please, if you make good tests, please let me know how it is... (faster, reliability, etc...)

EDITED: New 0.6 version Released, including the function RN_PacketGetPlayerIndex to know the index of the Player. Anyway the automatic index of raknet seems not to work perfectly and in the forums say that you must use your own.

Link: www.lcuriel.arrakis.es/RakNet0.6.rar

Now the help files are included in the rar file too. And the Test.bb file has more msg support for testing!

Stellar(Posted 2005) [#6]
hope you didn't plan this as your next userlibs product :(

KuRiX(Posted 2005) [#7]
3cho, i don't understand your post. This is a free wrapper i am doing for personal use but i want to share with all b3d users (future versions too). I want this to be the best udp multiplayer library for b3d.

And kode is not an userlib product.

I think i don't understand what you mean :(

Wayne(Posted 2005) [#8]
Thanks for the update Kurix.

I wish you'd offer a zip too.

Stellar(Posted 2005) [#9]
lol, sorry i mean your [K]ODE product
thx for wrapper

Xaron(Posted 2005) [#10]
Thx for the wrapper, it's great! Exactly what I need.

Regards - Xaron

KuRiX(Posted 2005) [#11]
Hey, i have changed some things in the DLL so now you can use the internal Indexes for the players.

So you can get a number from 0 to (MAXIMUMPLAYERS-1) from every packet you receive to know who has sent it!!!

Changes in the 0.7 version!

Great, huh? xD

@rtur(Posted 2005) [#12]
Thanks, very usefull!

Mustang(Posted 2005) [#13]
Hey, this could be useful... I'm not making any multiplayer stuff now but for future projects this would probably rock!

jfk EO-11110(Posted 2005) [#14]
Thanks a lot KuRiX for sharing your work. It seems RakNet is an excellent solution for MP stuff.

Maybe you can help me so I don't have to read tons of docs first: Is this architecture using one (the first) player as the game server? And if so, is it possible to hand over the server job to a client (eg. when the hosting player wants to quit without to end the game for the other players)?

KuRiX(Posted 2005) [#15]
Well, Raknet is a very very powerful library, and is still in development (so future updates will be possible).

You can use a peer to peer functions, or use the in built client server functions (that uses only the peer functions). The problem is that i have not wrapped yet all the peer to peer functions, because i only needed the client server and i needed asap.

Anyway there is a new version available (2.4) and i want to update the wrapper, and perhaps i will include some new functions.

I must say that i am using it for client sever game and is very fast and stable!

Cheers, KuRi!

jfk EO-11110(Posted 2005) [#16]
Thanks, I still don't fully understand what you mean by Client/Server vs Peer2peer. When you say you want to replace BlitzPlay then I assume it is using the same structure (one player is the host, the other players are clients).

Unfortunatly BlitzPlay doesn't support taking over the server task by an other client. Well, in the old (Freeware) version of BlitzPlay it was supported, but then SurReal rewrote the entire thing from scratch with a new concept and without the mentioned support for server takeover.

The reason why I want this feature is the fact that a game may last much longer when the intial host doesn't need to stay connected all the time.

KuRiX(Posted 2005) [#17]
Well, in some way, Blitzplay is based on peer2peer connection too.

Basically, in UDP, you have peers, that can connect to other peers. If you consider one peer as beeing the server (so it broadcasts all the messages), then it is a client/server (a client/server is always an abstract of peer2peer).

So, if you use a peer2peer connection and you decide who is the server, you can of course select other host when one leaves...

This is not easy to explain, but i can guarantee that you can do it (if i wrap all the peer functions of course, xD)

KuRiX(Posted 2005) [#18]
Due to the incremented interest in the raknet wrapper, the library has been updated to the latest version of raknet, the 2.4

You can download the latest version of the wrapper (the 0.75) in the top of this page!


jfk EO-11110(Posted 2005) [#19]
Thanks a lot for sharing. VERY useful work.

@rtur(Posted 2005) [#20]
Thanks KuRiX. Excellent work.

jfk EO-11110(Posted 2005) [#21]
RakNet is really much better than anything I tried yet. The seperate thread makes things very quick. Even with 3 clients onscreen on localhost it's still pretty fast. And it works pretty well together with ZoneAlarm Firewall. It asks one time (didn't even ask for server rights, surprisingly) per process. I've seen other solutions that required to lower the security level of zonealarm, or libs that used to throw a dozen of firewall alerts to the user (especially DirectPlay stuff).

There are a few drawbacks, eg: the RakNet Process will be listed as a nameless process in the task manager. This may be not a problem with the XP task manager that shows the file path, unlike win98/Me that will list the process name only. Looks pretty scary when you see blank processes in the manager (especially when you have no idea what it is).

And there have been a few messed up messages, like when I send a chat message and the server says "received data of unrecoginzed type" (or something). So I think it will be a good ideat to work out some acknowledge and error detection system, eg. a packet checksum. And a handshake that will allow the server to send the next packet.

Now I have a dumb question (probably I shoulda know, sorry): Is this System using UDP?

KuRiX(Posted 2005) [#22]
Well, here are a few answers.

First of all, Raknet is only UDP.

The second is, due to the first answer xD, that when a message arrives, arrives perfect. So, if you are having troubles sending chat messages i suggest you to send them like BitStreams insted of char *.

FarFlame are asking lot of questions to me via email. I think that this is a best place to ask. Perhaps i will post here his emails and my answers.

Cheers, KuRi.

t3K|Mac(Posted 2005) [#23]
i'll have to check out raknet with wrapper too.... looks good in any way ;)

KuRiX(Posted 2005) [#24]
I am working in a multiplayer raknet game, but i would really appreciate someone making a good raknet demo to include with my wrapper...


Jeroen(Posted 2005) [#25]
KuRiX: Great stuff!
I couldnt find out wheter Rakknet is PC only, or cross-platform...Do you happen to know?
If so, a module for BlitzMax could be created.

KuRiX(Posted 2005) [#26]
It is multiplatform!!! Tell me how, and i will make a BlitzMax Version!

Jeroen(Posted 2005) [#27]
Hi KuRiX,

I'm interested to use Raknet in a future project now being conceptualised and documented, a follow-up to a multiplayer game I have been working on in the past.

You'll have to write a "mod" for BlitzMax.
A simple example can be found here:

Jeroen(Posted 2005) [#28]
ps: KuRiX, I read it is also possible to work with a "master server" or some kind. How can it be done with your wrapper?

KuRiX(Posted 2005) [#29]
Mmm, interesting, so BMax can directly compile C Code! Wow!.

The problem is that i don't have BMax.

Anyway i think that including directly RakNet C Files will be very hard, it is programmed in hard C++. Is it possible to make a lib or dll for BMax?

And about the master server, the functions are not wrapped at this moment, but should be easy to do! I will look at them for the next wrapper version...

Jeroen(Posted 2005) [#30]
Hi KuRiX,

If you make a DLL, you are stuck to the Windows platform.
For BlitzMax development, IMHO not a wise decision.

Looking at the example, they "import" a C file.
You can do the same fromout BlitzMax: just import it,
you don't need to touch the C files.

To be honest, I lack experience on mod writing,
perhaps you could ask some more experienced mod writers
in the BlitzMax forums.

BlitzMax is the way to go for the future. I am waiting for the official 3D module for larger projects, but I love the language and it's worth buying! I'm not investing more time to program under Blitz3D for larger projects.

I have a Mac, so if you might decide to write the BlitzMax MOD, I'm happy to bugtest it for you.

Jeroen(Posted 2005) [#31]

KuRiX(Posted 2005) [#32]
Well, not having BMax, i don't see like so easy job. I will think of it later...

Jeroen(Posted 2005) [#33]
ok cool, I'll use Bnet instead

KuRiX(Posted 2005) [#34]
Thanks for your help anyway, very much appreciated!

KuRiX(Posted 2005) [#35]
Well, i have created a mini web page to download the latest version of raknet (still 0.75, very very stable).

I have received some emails about buying source code for the wrapper, so i have decided to add a button to buy the source code of the Raknet Wrapper, for those interested. (Visual C++ 6.0)

This could be of interest if you want to know how to develop a wrapper or if you want to add the rest of the functions to the wrapper by yourself.

However the compiled wrapper will always be free.

Cheers, KuRiX

RepeatUntil(Posted 2005) [#36]
I would be also VERY INTERESTED in a version of your wrapper for BlitzMax !!!!!! And I am sure it's the case for a LOT of people out there....

KuRiX(Posted 2005) [#37]
Is not possible to use the same dll for blitzmax? I don't have blitzmax...

Baystep Productions(Posted 2005) [#38]
Why do I keep getting a Server feed of "Unknown Message Type (Type = -1)"? I'm trying to use the example to fit my game but it's not working well. Any help? I just want to run an update for client, and a seperate update for server.

The functions included that are needed is a simple chat(broadcast), Player positions (x,y,z,"yaw"), and events (ie. explosion, bullets, activated somthing, etc).

Any helpers???

KuRiX(Posted 2005) [#39]
Post some basic code so i can help ;)

Baystep Productions(Posted 2005) [#40]
That's the problem I don't know where to start.

I want to use seperate Functions IE...

Function Host()
RakNet Here
End Function

Function Join()
Stuff Here
End Function

Function UpdateClient()
End Function

Function UpdateServer()
End Function

KuRiX(Posted 2005) [#41]
Well, let's begin:

; Initialize the server.
Global Server=RN_GetRakServerInterface()

;Initialize the client
ip$ = "localhost" ; CHANGE THIS TO THE SERVER IP
Global Client=RN_GetRakClientInterface()



This is only a sample of what you should do. It uses BitStreams instead of Strings (much much better). And please note that only internal messages are broadcast by server automatically. User messages (50-255) must be broadcasted manually.

Post any question you have here.

jfk EO-11110(Posted 2005) [#42]
Very useful, thanks a lot!
Now I only need to use Gnet instead of "localhost".

Baystep Productions(Posted 2005) [#43]
Good stuff!

But where do I add the player position codes.

KuRiX(Posted 2005) [#44]
Ok, suppose you want to send the x,y,z to the server, and then you want the server to broadcast this position to the rest of the players...

;Make a Global BitStream instead of once every time
Global BitStreamOut=RN_BitStreamCreate1(0)
ID_POSITION_UPDATE = 60 (for example)

Function SendPosition(entity)

End Function

Now in the receiving loop of the server:

;Make a Global BitStream instead of once every time
Global BitStreamIN=RN_BitStreamCreate1(0)
ID_POSITION_UPDATE = 60 (for example)

while (packet) ; bla bla bla


Select MessageID
     ;Here you update the local position

     ;Now BroadCast

As you can see i use always bitstreams for the sending and receiving, and it is the way you should do it. There are lot of other ways of doing this, but this is an example. Good Luck, and don't forget to read the documentation in the raknet official site!

Baystep Productions(Posted 2005) [#45]
I got a MAV on the RN_ServerSend2 part

KuRiX(Posted 2005) [#46]
- Be sure to have initialized the BitStreamIN Variable with RN_CreateBitStream1.

- Be sure that the Server Variable of the sample is the ServerInterface you have declared before!

And please, do not copy paste the code to avoid possibly typos in my code...

Baystep Productions(Posted 2005) [#47]

KuRiX(Posted 2005) [#48]
working now?

Baystep Productions(Posted 2005) [#49]
Slowly. Maybe It's cause Im running seperate clients and servers on the same system.

KuRiX(Posted 2005) [#50]
I have been running multiple clients and servers on one machine with no problem. Make sure you set the threadpriority to some value greater than zero so the thread is not cpu intensive...

10 could be a good value! ;)

P.D: Raknet 2.412 has been released. I will update the wrapper soon!

KuRiX(Posted 2005) [#51]
As i promised... Raknet Wrapper is now updated to the 2.415 version. 2.413 and 2.414 were bad updated. So, although this is supposed to be a good update, please make a copy of all your actual projects before updating!

Latest Version:


P.D: for those who bought the source code, if you are interested in the latest version, please email me (i don't send it automatically because i suppose they have changed everything already...)

KuRiX(Posted 2005) [#52]
Well, there are problems with Raknet Versions greater than 2.402 so i am going to stop updating the wrapper until a new stable version comes out...

If you want to use raknet wrapper get the 0.75 version of the wrapper (corresponding to the raknet version 2.402). It is a very very stable version with all the features in it...

I am going to release a commercial project soon and i will be using that version. Newer versions are getting very buggies. I hope Rakkar will take care with the bugs he is inserting due to fast releases...

Jeroen(Posted 2005) [#53]
KuRiX: GREAT wrapper, Raknet! Onward to BlitzMax :-)
Hint hint :-)

Battle Tanks(Posted 2006) [#54]
Look's good, I've downloaded it and will give it a go tomorrow, Viper from the JV-ODE Physics Thread Recomened raknet. should make a great team. O yes If you need Physics I would be happy to recomend JV-ODE or for the Thread JV-ODE Thread

KuRiX(Posted 2006) [#55]
Yes, RakNet is very good, and now is free for NON commercial use (visit www.rakkarsoft.com for commercial licenses)...

I have updated the wrapper to the latest version, that is working perfectly (2.484). If you are interested i can release it (if i get permission from rakkar).

boomboom(Posted 2006) [#56]
I have started playing with network stuff. And had a go with it last night. Raknet is pretty good, and this wrapper is quite swell :)

Just one thing, as this is my first Userlib. Is there spesific place to put the help files so that when you press F1 twice it opens the docs for the function?

KuRiX(Posted 2006) [#57]
The docs i attach with the wrapper are the original docs for raknet. I have not made a help file for every raknet wrapped command...

So you just put it wherever you want... because blitz3d will not automatically go to the help file...

Mikele(Posted 2006) [#58]
Release new version if you can, please :)

boomboom(Posted 2006) [#59]
Its always good to have the latest version.

KuRiX(Posted 2006) [#60]
Ok ok... here it is. This version is not backward compatible, or at least the file named raknet.bb (the only part not compatible is the packet enumerations). So check if you have correct numbers assigned to user packets.



boomboom(Posted 2006) [#61]
I tried that version (2483) and it crashed blitz with the test.bb's. Freezes and the window goes white, when the server is being initialised.

I went back to 075 and it worked fine again.

KuRiX(Posted 2006) [#62]
The test.bb file is not updated... but the new version works perfectly. I will try to update it later...

RepeatUntil(Posted 2006) [#63]
Coming back to BlitzMax and Raknet: it would be very nice to use Racknet with BlitzMax, this library seems so good!!
I am really not an expert, but I think we could use directly the source code of RackNet into BlitzMax, without the need for the dll (so that everything is cross-platform).
In the IDE, in the section "Language", there is a subsection "Advanced topics" which deals with importing C++ code... Do you guys think it will be possible/easy to do that with Racknet??
Reading this BlitzMax help, I see "Methods declared in an extern type must be declared virtual in the C++ class. " It seems it's a big limitation for wrapping RackNet. Any thoughts?

boomboom(Posted 2006) [#64]
well have a go RepeatUntil. The C++ source is avaliable on thier website.

KuRiX(Posted 2006) [#65]
I don't have blitzmax, and i have no much time now to investigate, but should be easy, with a little tricks...

RepeatUntil(Posted 2006) [#66]
So after some research, I conclude that it won't be easy to wrap RackNet for BlitzMax. It is possible, but it will require some non negligible work (and, no, I am not candidate ;-)

Racknet is written in C++ with objects and BlitzMax is able to import *only* methods which are virtual. Of course, none of the method in RackNet are virtual, so it's impossible to import directly the functions/methods.

So one of the solution is to wrap in C the C++ method. In fact in the C function you have to make a call to the method in C++ (see mod/Pub.Mod/freeAudio.Mod for an example of what I mean). So every functions that you want to export, you need a C function that wraps it. And then BlitzMax is able to call directly this function.

But this is a lot of work...

I am not a wrapper expert at all, so are other confirming what I just said?I would be happy that someone prove me wrong...

KuRiX(Posted 2006) [#67]
It is very possible that you are right, repeatuntil. Then, you would need to wrap all c++ functions into a c library, just like my wrapper.

Why can't you use the same dll i have made? Can't blitmax use dll's the same as with blitz3d?

VIP3R(Posted 2006) [#68]
Yeh, you can use the same DLL in BlitzMax Kuri ;)

RepeatUntil was talking about including the C/C++ source directly (as a module) instead of using a DLL, so that it would work cross-platform. Using DLLs in BlitzMax will of course only work on the Win32 platforms.

Good luck with the Granada Racer, its release can't be far away now :)

RepeatUntil(Posted 2006) [#69]
Yes, VIP3R said it all: we have to include the c/c++ code so that it's cross-platform. Using your dll will lose this feature, and that's something we don't want to lose in BlitzMax.

BUT now I realize that you already did the job for BlitzMax, Kurix!! I guess you wrapped all c++ functions into c functions, getting rid of object. So that's exactly what BlitzMax need to have, and include that directly into BlitzMax (and then just make an extern statement to declare functions).

So I think the wrapper for BlitzMax is just around the corner with a little extra work, using the wrapper of Kurix.
Kurix, would it be possible that you show us one or two functions (the code in C) you have wrapped, just to make sure your code will work with BlitzMax. I know that the wrapper code is not free, but I would like just to see 2 functions to see if that would fit.....

By the way, stupid question: you used visual C++, but of course one could re-use your code using devcpp??


KuRiX(Posted 2006) [#70]
Well, wrapping Raknet is an easy job, but you need to make some little tricks, as i commented before, for example to use the UNASSIGNED_PLAYER_ID struct as C.

Two samples of the wrapper:

and of course don't forget to include all the header files and the raknetstaticlib!

RepeatUntil(Posted 2006) [#71]
Thank you very much, Kurix!
So the conclusion is that RackNet could be wrapped in BlitzMax without hundreds of hours of work. And it seems that the wrapper that Kurix already wrote would work perfectly for BlitzMax, with little modification (if Kurix agrees that someone use his wrapper for BlitzMax, after paying the 20$ for the source).

RackNet, the best networking solution, would be cross-platform for BlitzMax!! That would be neat!! But now the question:
who would like to do the work????
(noooo, I am not candidate by terrible lack of time)

KuRiX(Posted 2006) [#72]
But then... in blitzmax, you can import all the raknet source and then, with a wrapper .cpp you can call them?

Well, i have no time now, but in two months i could check it ;)

RepeatUntil(Posted 2006) [#73]

But then... in blitzmax, you can import all the raknet source and then, with a wrapper .cpp you can call them?

Basically, I see things like this:
- import in BlitzMax the wrapper you did, without any modification (I hope!)
- In this blitzMax file, add an extern..end extern command where you declare all functions you want to use (The equivalent of the .decls file for BlitzBasic)
- That's it!
So, it seems to me that this work could be pretty simple, like a couple of hours...... But I am sure a lot of issues will arise, and that won't be so simple...

That said, after you could go further, and wrap in BlitzMax the C function to use BlitzMax type to have object orientation!! But that's another level of complexity, and I am not sure it would be useful!

This is the example taken from the help file of BlitzMax:
//----- file: c_funcs.c -----
int Doubler( int x ){
	return x+x;

'----- file: app.bmx -----
Import "c_funcs.c"

	Function Doubler( x )
End Extern

Print Doubler(10)

Well, i have no time now, but in two months i could check it ;)

But you told us you haven't BlitzMax?! Let's see if someone would be interested to do that, if not, then we all count on you in 2 months!!!!!

KuRiX(Posted 2006) [#74]
I guess i will buy it, sooner or later, and two months is a good time to decide!

RepeatUntil(Posted 2006) [#75]
On the site of RackNet, I read this:

Use the source or a DLL?

RakNet includes the source and a pre-made DLL, along with sample projects to make a DLL, use a DLL, and use the source. You may use either in your game. During development, you will probably want to use the source so you can trace into the code for better control. During release, you will probably want to use a DLL so you don't have to make your game multithreaded, and for easier patching.

In BlitzMax, we will use the source of course (from cross-platform). But then I am worried by the fact that including the source means that the game will be multithreaded!! Is it compatible with BlitzMax?? If BlitzMax is not tread-safe, is it not a show-stopper?? Thanks to give opinion on that...

KuRiX(Posted 2006) [#76]
Anyway... why not using a dll just like with blitz3d?

RepeatUntil(Posted 2006) [#77]
Because we want to have Racknet on all 3 platforms supported by BlitzMax (Windows, Linux and Mac). A dll is only for windows. If you include the source, since Racknet is already multi-platform, you will have automatically the "auto-platformity".
And this is very important for BlitzMax users to use lib which are multiplatform, this is always a plus.
So I don't see other solutions, other than including the source. But then I am not sure if the multithread is a problem for BlitzMax....

RepeatUntil(Posted 2006) [#78]
I opened a new discussion in the BlitzMax forum, to get attention of BlitzMax users (and some opinion):

KuRiX(Posted 2006) [#79]
Thanks to Farflame i have detected that i had not updated the raknet.bb file in the last wrapper! so it wasn't working at all!!!

Now is fixed. Download it and enjoy Raknet! (and remember, free for NON commercial use).

Filax(Posted 2007) [#80]
Any news about this wrapper ? :)

t3K|Mac(Posted 2007) [#81]
yeah, good question...

Stu_ovine(Posted 2007) [#82]
dead project I believe .... we could do with someone taking the lead on this and rolling us a wrapper for RakNet v3.0. hint hint anyone ? :)

Saying that the wrapper is perfectly functionaly (well coped with everything I needed)

Filax(Posted 2007) [#83]
Here is the wrapper converted for blitzmax, but i get problems with samples ;/

t3K|Mac(Posted 2007) [#84]
Is Kurix still around here?

t3K|Mac(Posted 2007) [#85]
i just wanted to reanimate this thread... is kurix alive?

RepeatUntil(Posted 2007) [#86]
As said in another thread, I will post a wrapped version of RakNet 3.0 (the latest RakNet version). This will be for BlitzMax, but then somebody can write a decls file (not me).
More news later...

t3K|Mac(Posted 2007) [#87]
good to hear!!