Hazel Networking - Open Source RUDP/TCP Library

Hi Jamster! Nice work! Did you know library Lidgren? Can you please provide a short list of pros/cons compared with it? As I remember, lidgren uses only UDP+RUDP.

I did know about Lidgren, I’ve never used it though!

Pros for Hazel:

  • Supported by a commercial product so will be constantly maintained.
  • Designed for speed.
  • Supports TCP and UDP/RUDP and is easily extendible for other transport methods (Lidgren only supports UDP/RUDP.
  • Very easy to swap between transport methods.
  • Will support web sockets in the future (not possible with Lidgren).
  • Fully thread safe (not sure about Lidgren on this one).

Pros for Lidgren:

  • Fragmented packets on RUDP (Hazel will probably have this at some point).
  • Ordered packets on RUDP (Hazel may have this at some point but it’s unlikely).
  • Bigger community/more widely known/more established.

If there are any other points to add to/mistakes in this list please post them and I’ll add/change them :slight_smile:

Jamie

1 Like

Hi,

I may be interested in testing your library with our game, but I’d like to know more about it.

We are interested only in the low level support, since we manage states synchronisation with our custom code, but I’d like to understand better the difference between Hazel and Darkrift.

All that said, we currently don’t need the fragment packets feature, all our packets are smaller than the MTU, but I am not sure how you can manage state synchronisation without the ordered packet feature. Do you design your game around this limitation?

1 Like

Brilliant!

DarkRift is a fairly low level networking solution, akin to a halfway house between Unity’s HLAPI and LLAPI (it doesn’t use either of these however). Hazel on the other hand is a low level networking library that DarkRift 2 is being written upon, more akin to Lidgren. DarkRift has higher level concepts like clients etc. and distributes messages etc., Hazel only handles connection - you pass it data and it sends/receives it, no distribution, IDs etc.

If it helps make things clearer Hazel is built on Sockets, DarkRift 2 will be built on Hazel :slight_smile:

Ordered packets are tricky because Hazel is so multithreaded, even if Hazel did order packets as soon as it invokes the message received events if they were in separate threads the packets could end up out of order… I might add something similar to ordered packets in the future but it wont be simple :frowning:

In most circumstances you would probably just send unreliable packets and display the most recently received state but if you absolutely need order you could append an order byte/ushort and receive reliable packets into a priority queue/heap or receive unreliable packets and simply display that state if the order value is greater than the current displayed, whichever is more suitable for your game.

Jamie

If I only use the Hazel TCPConnector, will that occur?

I had transfered to UNET LLAPI last week, since i very need the WebGL support both at client and server side.
But, it is a nightmare, hard to use and crash much.

So finally i wrote a adapter, it can switch between UNET and Hazel. I have to say, hazel is my current choose, it’s stable and fast, and I like the API design, simple and efficient. I really need the webgl support, maybe i could write for it when i have time.

Sadly a limitation of Hazel is that even with TCP it can’t guarantee order :frowning: It’s designed for speed (hence it’s use of multiple threads) rather than ordered packets, though with TCP it would be a lot easier to modify it to your needs.

I will try and think how Hazel could handle ordered packets, it seems people want it! :stuck_out_tongue:

Yes Indeed, please make it can be ordered.

Hello i have been using Darkrift for a while now, i was wondering if you have any plan on adding SSL support at some point?

oh and by the way i was able to use nginx as a proxy server for Darkrift 1.
It works very well and clients are balanced accross servers and data are shared using memcached server.
And when ever i need to trigger an event to a client which is currently not connected on the server instance i send the trigger event to the master server which then send it to the appropriate server.

I have no plans to implement SSL as I have only a fairly limited knowledge of encryption/web security and I’m not sure how much demand there is for it. For any secure communications I’d always recommend having it via a HTTPS server on the side…

That’s awesome! I’m glad that’s working well for you! Hopefully DarkRift 2 will have its own dedicated proxy application that might give you a performance boost and be a lot easier to configure!

Jamie

Just when I thought I was going to have to write this myself! This library looks excellent. I’m just curious, how has the process been with writing this library as opposed to using Unity’s own networking library or a solution like Photon? I’m assuming we can use our own server with this?

I’m not sure I fully understand your question but I’ll try and answer it!

Hazel is much much more low level than Photon and UNET, they understand things like ‘players’ etc. Think of Hazel more as a pipe, you put a message in and they come out the other side, that’s all it does and you don’t need to think about how the pipe gets your messages there it just does!

(I cant believe I just reduced Hazel to a pipe analogy…)

You answered well, apologies if I wasn’t clear. That’s perfect, I was more curious about the actual process, as in did you hit any roadblocks or are there major issues that you came across with working at the socket level alongside Unity? That makes sense that it is just for sending messages back and forth across TCP and UDP, now I just have to worry about client prediction and lag compensation :wink:

I am currently working on an RTS mobile game where we didn’t want to use any of the existing libraries (Unet, Photon etc) due to their pricing model and also the fact that we wanted to build everything in house and have control over our data flow. Will give Hazel Client a go tonight!

Hazel was completely developed outside of Unity actually, my main goal was to make it cross platform (and so at some point I will probably introduce a Java version as well) hence I did it outside and then made sure it worked within Unity after. It wont work on the platforms that don’t enable sockets (I’ve frankly lost track of which Unity licenses you need now…)

I think the next step is to do websockets but I feel like that’s going to be 2 different projects, one for within Unity built from calls down to Javascript then to websockets and then one for outside Unity written purely in C#.

1 Like

Hi folks, i have worked with Hazel for a time, in the meanwhile, i actually played with LLAPI of UNET as well. Also worked the pure Socket at the beginning.
I would say, Hazel is excellent, i love the pattern it use (like pipes yes). After 2 month facing on the networking, i finally make Hazel work in my official project - a fps kind game, but with some modification to support WebGL, yes i implemented WebSocket based on Hazel and jonas’ websocket class. Based on Hazel’s good structure, it is easy to add a implementation.

@Jamster , i have modified the TcpConnection.BodyReadCallback method to :

        void BodyReadCallback(byte[] bytes, bool mask)
        {
            Statistics.LogReceive(bytes.Length, bytes.Length + 4);

            //Fire DataReceived event
            InvokeDataReceived(bytes, SendOption.FragmentedReliable);

            //Begin receiving from the start
            StartWaitingForHeader();
        }

It seems fixed the issue of

Not tested much, please check am i right for the modification.

1 Like

Brilliant!

Your modification should work and guarantee order yes :slight_smile: I will probably add something like that/a toggle that will allow that as that a much neater solution to what I was thinking!

Jamie

Added some bug fixes to TCP for those interested :slight_smile:

1 Like

What did you add?
Did you already pushed it on your repo? :smile:

There were a couple of points where it wasn’t handling disconnections properly, already pushed :slight_smile:

1 Like

Hazel has seen a couple of improvements,firstly I’ve added the ability to send a portion of bytes with the initial connection packet, this allows you to send details about your client and any additional data you may need to send before communication actually begins.

I’ve also added a major security patch that was allowing people to crash TCP connections by sending malformed packets (funnily enough, exactly those that telnet sends if you connect with it!). Thanks to Terry for pointing that one out!

Rewards may be available for significant bugs found in DarkRift/Hazel! :wink:

1 Like

Is anyone having a problem using Hazel in Unity builds?

Currently using Unity 5.5.2 and whenever I build to Windows standalone I get errors trying to connect and nothing trying to receive… just me?