Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Hazel Networking - Open Source RUDP/TCP Library

Discussion in 'Multiplayer' started by Jamster, Jun 8, 2016.

  1. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    1,102
    Turns out at some point I changed the UDP resend timeout to 200, that I think broke stuff so a fix has been released t all channels!

    Jamie
     
  2. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    1,102
    I've added a bug fix on disconnections in UDP and a few minor refactorings :)
     
    ManHunterITA likes this.
  3. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Looks pretty neat. I've just been looking at GameSparks's real-time API, but it seems fairly low-level to me... if I have to do all that, I think I may as well use Hazel.

    Is there any reason I can't use Hazel in a peer-to-peer mode? That is, have the "server" actually be one of the clients, to which all the other clients connect? This would be intended mainly for LAN play, though I suppose you could use it over a WAN with appropriate firewall/router settings.
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    ...OK, I give up. Where is the documentation? All the links in the repo point to http://www.darkriftnetworking.com/docs, which is 404 Not Found. And so I tried lopping /docs off of that URL, but that produces a 403 Forbidden error. It appears you have a domain name and web server, but no actual home page (index.html or similar) there?

    Is this project even still alive?
     
  5. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    1,102
    Hey Joe, Hazel will work for LAN but there's no NAT punch through so if you wanted to implement anything over the internet your users would have to port forward their routers as you say.

    The project is still very much alive its just my website hosts are pretty useless and have changed a setting on the server which has broken my site again... Sorry!

    ADDED: The documentation is auto generated from the docs folder using Sandcastle, any information online is also in there!
     
    JoeStrout likes this.
  6. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    1,102
    Website should be back online, it appears they replaced the entire contents of the website with a single, undeletable folder... o_O
     
  7. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Sure. My thinking was, if this project ever gets serious enough, I would probably try NAT Traversal to solve that issue.

    Hah. Yep, looks good now; thanks for the quick fix. I spent last evening looking at a lot of different networking options, but honestly, I think Hazel is the right level for me. I'll let you know how it goes!
     
  8. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Ran into a compiler error upon adding the code to Unity:

    By the way, I do quite appreciate that you're making Hazel generic C# code, such that one could build a command-line server. I can see all sorts of uses for that. But, of course it needs to work in Unity too.

    It looks like I can fix this error by changing UdpConnection.cs:13 to

    Code (csharp):
    1.        public int FragmentSize { get { return 65507 - 1 - 2 - 2 - 2; } }
    But now I have several more errors in the examples, all along the lines of:

    But deleting the DocIncludes folder seems to have fixed that.

    For the future, I might suggest either a Unity QuickStart doc that tells you what to import into Unity, or maybe a restructuring of the file hierarchy so that there is an obvious folder that contains everything you need, and nothing you don't (e.g. "Source" or similar).

    Anyway, all errors gone now... super excited!
     
  9. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    OK, first real question.

    How do I find out the IP address my UdpConnectionListener is listening on? This should be the address that clients type in to connect.

    I tried displaying (listener as UdpConnectionListener).EndPoint, but this just shows 0.0.0.0 (and the correct port number).

    I know there are standard ways of finding local IP addresses, but on a machine with multiple network interfaces, it can be hard to find out which IP address the server is actually listening on. Isn't there some way to get this from Hazel?
     
  10. Obsurveyor

    Obsurveyor

    Joined:
    Nov 22, 2012
    Posts:
    277
    0.0.0.0 means that it's listening on all IP addresses. It's a "meta-address". If you want to listen on a specific IP address, you specify it, the library doesn't pick it. Most network software works this way.
     
  11. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Hmm. So if I have 3 active network interfaces, it listens on all three? I find that very surprising.

    I guess the practical question is still: which address should I show to the user? Just pick the first active one I can find?
     
  12. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Hey, in case it's useful to anyone, here's the MonoBehaviour I came up with this morning for a UDP client/server in Unity. You just put this on some object in the scene, and then call either StartServer or StartClient (with an IP address).

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Events;
    3. using System.Collections.Generic;
    4. using System.Net;
    5. using Hazel;
    6. using Hazel.Udp;
    7.  
    8. public class Network : MonoBehaviour {
    9.    
    10.     public int portNumber = 4296;
    11.    
    12.     static Network _instance;
    13.    
    14.     // Server Data
    15.     ConnectionListener listener;
    16.     List<Connection> clients = new List<Connection>();
    17.    
    18.     // Client Data
    19.     Connection serverConn;
    20.    
    21.     public static Network instance {
    22.         get {
    23.             if (_instance == null) {
    24.                 _instance = FindObjectOfType<Network>();
    25.                 Debug.Assert(_instance != null);
    26.             }
    27.             return _instance;
    28.         }
    29.     }
    30.    
    31.     void Awake() {
    32.         if (_instance == null) _instance = this;
    33.         else Destroy(gameObject);
    34.     }
    35.    
    36.     void Start() {
    37.         MessageLog.Print("Network idle.");
    38.     }
    39.    
    40.     void OnDestroy() {
    41.         if (listener != null) listener.Close();
    42.         if (serverConn != null) serverConn.Close();
    43.         foreach (var conn in clients) conn.Close();
    44.     }
    45.    
    46.     #region Server
    47.     public void StartServer() {
    48.         NetworkEndPoint endPoint = new NetworkEndPoint(IPAddress.Any, portNumber);
    49.         listener = new UdpConnectionListener(endPoint);
    50.         listener.NewConnection += NewConnectionHandler;
    51.         listener.Start();
    52.         MessageLog.Print("Server listenening on " + (listener as UdpConnectionListener).EndPoint);
    53.     }
    54.    
    55.     void NewConnectionHandler(object sender, NewConnectionEventArgs args) {
    56.         MessageLog.Print("New connection from " + args.Connection.EndPoint);
    57.         clients.Add(args.Connection);
    58.         args.Connection.DataReceived += HandleDataFromClient;
    59.         args.Connection.Disconnected += HandleClientDisconnect;
    60.         args.Recycle();
    61.     }
    62.    
    63.     void HandleDataFromClient(object sender, DataReceivedEventArgs args) {
    64.         Connection connection = (Connection)sender;
    65.         MessageLog.Print("Received " + args.Bytes.Length + " bytes from client at " + connection.EndPoint);
    66.         //connection.SendBytes(args.Bytes, args.SendOption);      
    67.         args.Recycle();
    68.     }
    69.    
    70.     void HandleClientDisconnect(object sender, DisconnectedEventArgs args) {
    71.         Connection connection = (Connection)sender;
    72.         MessageLog.Print("Connection from " + connection.EndPoint + " lost");
    73.         clients.Remove(connection);
    74.         args.Recycle();
    75.     }
    76.    
    77.     #endregion
    78.    
    79.     #region Client
    80.    
    81.     public void StartClient(string ipAddress) {
    82.         NetworkEndPoint endPoint = new NetworkEndPoint(ipAddress, portNumber);
    83.         serverConn = new UdpClientConnection(endPoint);
    84.         serverConn.DataReceived += HandleDataFromServer;
    85.         MessageLog.Print("Connecting to " + endPoint);
    86.         serverConn.Connect();
    87.     }
    88.    
    89.     void HandleDataFromServer(object sender, DataReceivedEventArgs args) {
    90.         Connection connection = (Connection)sender;
    91.         MessageLog.Print("Received " + args.Bytes.Length + " bytes from server at " + connection.EndPoint.ToString());
    92.         //connection.SendBytes(args.Bytes, args.SendOption);      
    93.         args.Recycle();
    94.     }
    95.    
    96.     void HandleServerDisconnect(object sender, DisconnectedEventArgs args) {
    97.         Connection connection = (Connection)sender;
    98.         MessageLog.Print("Server connection at " + connection.EndPoint + " lost");
    99.         serverConn = null;
    100.         args.Recycle();
    101.     }
    102.     #endregion
    103.    
    104. }
    Just a couple of caveats:

    1. The MessageLog.Print thing I'm using here is my own little on-screen console. This has to be thread-safe; in other words, it should just throw its argument onto a Queue, and then pull strings off that Queue to actually display in Update, because it will get called from secondary threads by the various Hazel events.

    2. The Connect() methods block (freezing your whole game) until they succeed or time out. So, they really should be done in a thread too. But I'm ignoring this for now, and hoping that Hazel will at some point get a non-blocking option that makes this easier for us. ;)
     
    kalondar, Vytek and Jamster like this.
  13. Obsurveyor

    Obsurveyor

    Joined:
    Nov 22, 2012
    Posts:
    277
    Show them 0.0.0.0:<PORTNUMBER> if that's what you're listening on, if you have to show them something at all. Anything else will just confuse users that know how networking works when they can't open holes in their firewall or get their routing working properly. Users who don't know what it means don't really matter in this instance, imo.

    UDP is connectionless, so theoretically the IP could change every time you receive a new packet but this is highly unlikely without some intentional misbehavior going on.
     
  14. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Hmm, so you're saying that specifying 0.0.0.0 as the endpoint in UdpClientConnection actually works?

    In a quick test it appears to, but then I'm running both client and server on the same machine. I'll test on different machines later today.

    But if I were using TCP instead of UDP, then I would certainly need the user to enter a host IP address... and in that case, I should show a useful address on the host, as every other LAN game I have ever played does. So the question still applies.
     
  15. Obsurveyor

    Obsurveyor

    Joined:
    Nov 22, 2012
    Posts:
    277
    You can listen on 0.0.0.0 with TCP too...
     
  16. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    1,102
    Yes, 0.0.0.0 is the special IP address for any (at least in IPv4) and should work with TCP or UDP :) For clarification, if needed, if you have multiple IP addresses assigned to your computer then any one of them can be connected to. If you'd rather specify one then you can do that when creating the listener.

    Regarding the errors in Unity, I'd generally advise just adding the DLL/NuGet package rather than cloning the project for simplicity and ease of upgrading but if you need the source then you have a fair point and it shouldn't throw errors! Also the DocInclude folder got accidently included in the last NuGet package anyway!

    I'd forgotten about connecting in the background so it's been added to the todo list, that's for reminding me :)

    On a separate note, I spent today moving things to Visual Studio Team Services so Hazel now has continuous integration and the deployment process is so much simpler for me! Highly recommended :)
     
  17. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    OK, that's neat. But it still leaves the practical question: what to show to the user? I guess I'll just pick the first active interface, using one of the answers here. That should be good enough for the vast majority of users, perhaps excluding Linux. I'm still a bit surprised there isn't a standard solution, though.

    I don't have NuGet, so it was easier for me to just download the repo and throw in the source. And it was really just the one real error (UdpConnection.cs line 13).

    I've now got a basic multiplayer demo up and running about: one player hosts, the other connects, and as one moves around they can be seen to move in the same way on the other machine. The rest is just details. :) Thanks for making Hazel available!
     
    Jamster likes this.
  18. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    1,102
    In that circumstance I'd be inclined to show them all the IP addresses they can connect to since if you just choose the first you could accidently show them 127.0.0.1 etc. It also gives them other options if for some reason one doesn't work.

    On the other hand, almost all computers on a LAN are only likely to have one IP address allocated to them from the router unless the user has done something special, in which case they can probably work it out themselves :)
     
    JoeStrout likes this.
  19. Vytek

    Vytek

    Joined:
    Apr 29, 2016
    Posts:
    51
    HI Jamster,
    I start to test your Hazel Library using Xamarin Studio.

    I copy your server example from docs, but I have this problems:
    See attach image ;-)

    Can someone help me.
    Sorry for newbies question/problem.

    Thanks in advance.

    My config:

    === Xamarin Studio Community ===

    Version 6.3 (build 863)
    Installation UUID: 862f404a-3150-41c8-b081-97af6f384151
    Runtime:
    Mono 4.8.0 (mono-4.8.0-branch/9d74414) (64-bit)
    GTK+ 2.24.23 (Raleigh theme)

    Package version: 408000524

    === NuGet ===

    Versione: 3.5.0.0

    === Xamarin.Profiler ===

    '/Applications/Xamarin Profiler.app' not found

    === Apple Developer Tools ===

    Xcode 8.2.1 (11766.1)
    Build 8C1002

    === Xamarin.Mac ===

    Xamarin.Mac not installed. Can't find /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/Version.

    === Xamarin.Android ===

    Non installato

    === Xamarin Inspector ===

    Not Installed

    === Xamarin.iOS ===

    Xamarin.iOS not installed.
    Can't find mtouch or the Version file at /Library/Frameworks/Xamarin.iOS.framework/Versions/Current.

    === Build Information ===

    Release ID: 603000863
    Git revision: a2163670efe259c85cd8f335d95b175068fbbe2a
    Build date: 2017-04-03 14:33:15-04
    Xamarin addins: 2045d688ea1420e0381b473360ca62a763eb7d04
    Build lane: monodevelop-lion-d15-1

    === Operating System ===

    Mac OS X 10.11.6
    Darwin MacBook-Pro-di-Enrico.local 15.6.0 Darwin Kernel Version 15.6.0
    Mon Aug 29 20:21:34 PDT 2016
    root:xnu-3248.60.11~1/RELEASE_X86_64 x86_64
     

    Attached Files:

  20. Vytek

    Vytek

    Joined:
    Apr 29, 2016
    Posts:
    51
    Problem solved, but the demo/example in documentation will be update:

    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Text;
    5. using System.Threading.Tasks;
    6. using System.Net;
    7. using Hazel;
    8. using Hazel.Tcp;
    9.  
    10. namespace DarkRiftHazelTest
    11. {
    12.     public class HazelServerExample
    13.     {
    14.         static ConnectionListener listener;
    15.  
    16.         public static void Main(string[] args)
    17.         {
    18.             NetworkEndPoint endPoint = new NetworkEndPoint(IPAddress.Any, 4296);
    19.  
    20.             listener = new TcpConnectionListener(endPoint);
    21.  
    22.             listener.NewConnection += NewConnectionHandler;
    23.  
    24.             Console.WriteLine("Starting server!");
    25.  
    26.             listener.Start();
    27.  
    28.             Console.WriteLine("Press any key to continue...");
    29.  
    30.             Console.ReadKey();
    31.  
    32.             listener.Close();
    33.         }
    34.  
    35.         static void NewConnectionHandler(object sender, NewConnectionEventArgs args)
    36.         {
    37.             Console.WriteLine("New connection from " + args.Connection.EndPoint.ToString());
    38.  
    39.             args.Connection.DataReceived += DataReceivedHandler;
    40.  
    41.             args.Recycle();
    42.         }
    43.  
    44.         private static void DataReceivedHandler(object sender, DataReceivedEventArgs args)
    45.         {
    46.             Connection connection = (Connection)sender;
    47.  
    48.             Console.WriteLine("Received (" + string.Join<byte>(", ", args.Bytes) + ") from " + connection.EndPoint.ToString());
    49.  
    50.             connection.SendBytes(args.Bytes, args.SendOption);
    51.  
    52.             args.Recycle();  
    53.         }
    54.     }
    55. }
    I will create a new project example on github.

     
  21. Vytek

    Vytek

    Joined:
    Apr 29, 2016
    Posts:
    51
  22. Vytek

    Vytek

    Joined:
    Apr 29, 2016
    Posts:
    51
    Hi Jamster,
    how I create a more solid Server? ThreadPool? Any examples?

    Thanks in advance.
     
  23. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    1,102
    Can you define what you mean by "solid"? Do you mean more fault tolerant or something?
     
  24. Vytek

    Vytek

    Joined:
    Apr 29, 2016
    Posts:
    51
  25. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    1,102
    Well you can optimise for speed or more clients by adjusting the thread pool values as he does which will give Hazel more or less concurrency. Hazel is already nonblocking so you don't need to make any adjustments there :)
     
  26. Vytek

    Vytek

    Joined:
    Apr 29, 2016
    Posts:
    51
    Thanks for your help. Can your write a very little stub to start using ThreadPool? My target is to create a simple ChatServer example in TCP and RUDP.

    Thanks for your help.
     
  27. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    1,102
    I'm confused, Hazel already uses the threadpool to pass process data and all events are fired from the threadpool anyway so I'm unsure what you want?
     
  28. Vytek

    Vytek

    Joined:
    Apr 29, 2016
    Posts:
    51
    I am very sorry, there is misunderstanding.
    How can I create a Chat Server using Hazel?
    How can I create a simple routing system to broadcast single data received from a client to all client using a clients-server architetture (classical start network:https://en.wikipedia.org/wiki/Star_network) and Hazel as main library/protocol? I write a stub, but I have problem with pattern, objects to use and how to use Hazel to target this type of server.
    Thank you for your patience and help.
    All code will be opensource and I hope useful.

    This is a stub:

    Code (CSharp):
    1. using System;
    2. using System.Threading;
    3. using System.Threading.Tasks;
    4. using System.Net;
    5. using System.Collections;
    6. using System.Collections.Generic;
    7. using System.Text;
    8.  
    9. using Hazel;
    10. using Hazel.Tcp;
    11.  
    12. namespace HazelTestSuperServer
    13. {
    14.     public class Server
    15.     {
    16.         public static Hashtable clientList = new Hashtable(); //Using this?
    17.  
    18.         public int portNumber = 4296;
    19.  
    20.         private int counter = 0;
    21.  
    22.         public bool Running { get; private set; }
    23.  
    24.         List<Connection> clients = new List<Connection>(); //Or this? :(
    25.  
    26.         public void Start()
    27.         {
    28.             NetworkEndPoint endPoint = new NetworkEndPoint(IPAddress.Any, portNumber);
    29.             ConnectionListener listener = new TcpConnectionListener(endPoint);
    30.             Running = true;
    31.             listener.Start();
    32.  
    33.             while (Running)
    34.             {
    35.                 //Start listening for new connection events
    36.                 listener.NewConnection += delegate(object sender, NewConnectionEventArgs args)
    37.                 {
    38.                     //Add client counter
    39.                     counter += 1;
    40.                     //Add Connection to List
    41.                     clients.Add(args.Connection);
    42.                 };
    43.               }
    44.  
    45.             //Close all
    46.         }
    47.  
    48.         public void Shutdown()
    49.         {
    50.             if (Running)
    51.             {
    52.                 Running = false;
    53.                 Console.WriteLine("Shutting down the Hazel Server...");
    54.            }
    55.     }
    56.  
    57.     class MainClass
    58.     {
    59.         public static void Main(string[] args)
    60.         {
    61.             Server ServerHazel = new Server();
    62.             ServerHazel.Start();
    63.         }
    64.     }
    65. }
    66.  
     
  29. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    1,102
    I would personally use the List, but that's because I've not used the Hashtable before.

    In your NewConnection callback you need to subscribe to the data coming from that client (off the top of my head, it's called MessageReceived). You'll then get a new callback whenever a message is received and you can iterate over each client and send on the message to them.

    Don't forget that because all events are from /different threads you'll need to have some form of locking in there.

    Does that help?
     
  30. Vytek

    Vytek

    Joined:
    Apr 29, 2016
    Posts:
    51
    Yes, thank you!
    Could write a little stub/example?

    Thanks.
     
  31. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Isn't my code above (March 25) pretty much exactly that?
     
  32. Vytek

    Vytek

    Joined:
    Apr 29, 2016
    Posts:
    51
    Hi,
    your code is very cool and interesting, but it is for Unity.
    Using your code I start creating an example of Server and Client for C# console applications.
    Now I want to create a C# server console application using it as a Daemon by differents clients.
    I think that a Chat Server is a good example and starter point.

    Please see: https://github.com/Vytek/HazelTest
    (https://github.com/Vytek/HazelTest/tree/master/HazelTestSuperServer)

     
  33. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    I see. But the only Unity-specific bits are Awake, Start, and OnDestroy. If you simply replace those (or even more simply, call them at the appropriate times from your C# main program), I think it should work fine.
     
    Vytek likes this.
  34. rahuxx

    rahuxx

    Joined:
    May 8, 2009
    Posts:
    537
    Is there any tutorial for making hazel work in unity. Like starting guide?

    Rahu
     
  35. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    1,102
    There's no guide for making it work with Unity but if you follow the examples online it's not too hard to get it working!
     
  36. rahuxx

    rahuxx

    Joined:
    May 8, 2009
    Posts:
    537
    where is the example, please give link.
    Sorry for asking directly.
    Rahu
     
  37. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    1,102
    It appears to be missing! I'll get the sorted some point this week and post back for you!
     
    rahuxx likes this.
  38. Vytek

    Vytek

    Joined:
    Apr 29, 2016
    Posts:
    51
    rahuxx likes this.
  39. rahuxx

    rahuxx

    Joined:
    May 8, 2009
    Posts:
    537
    I am very new to this networking stuff. Will check and definitely try to give my inputs on this. By the way how to start server? From c# project of server or from Unity?
    Rahu
     
  40. Vytek

    Vytek

    Joined:
    Apr 29, 2016
    Posts:
    51
    Server is a console program so Download and run it (for Mono: mono <consoleprogram.exe>)

    Unity client is for Unity 2017.1f3: https://github.com/Vytek/HazelTestUDPClientUnity

    Warning it is a only a stub, I am writing a simple send/receive message using flatbuffer serialization.
     
  41. Supergeek

    Supergeek

    Joined:
    Aug 13, 2010
    Posts:
    103
    Does Hazel work in .NET Core yet?
     
  42. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    1,102
    Not yet, I've had very little time to work on this recently!
     
  43. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    1,102
    Ok the help docs should be available here. Makes more sense to have it there than the docs subdomain since there's now 2 docs on there! I'll update the website and GitHub tomorrow :)
     
  44. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    1,102
    After a long break, I have fixed a compilation issue that slipped through from a pull request and also made some bug fixes for issues that had been reported but I'd never finished fixing!

    Interesting to see Hazel now has 77 stars! Awesome!
     
    JoeStrout likes this.
  45. kalondar

    kalondar

    Joined:
    Nov 2, 2017
    Posts:
    1
    You have 78 :)
     
    Jamster likes this.
  46. The_Devil

    The_Devil

    Joined:
    Jun 6, 2015
    Posts:
    36
    Hi,
    Is there a way to calculate the ping between two connected clients?
     
  47. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    1,102
    There isn't at the moment, perhaps it's some thing you can add and create a pull request for?

    Either way, create an issue for it on the GitHub!
     
  48. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    Hi,
    I'm currently looking for a networking library that provides connection handling / fragmentation(and re-assembling of packets),

    1) I didn't find anything about that, but it does seem like Hazel does not have any sort of serializer. Is that right? But if it does have one, can it be disabled/bypassed? I want to use my own serialization library.

    2) It seems it only supports sending byte-arrays, which is pretty much perfect for me, but am I correct in assuming that it handles fragmentation / re-assembling of packets? Will I ever get incomplete data that I have to re-assemble myself? What about switching between UDP and TCP, will that change anything in that regard?

    3) Is this information here up to date?
    https://www.darkriftnetworking.com/Hazel/Docs/html/a3d0767d-2da3-45d2-80d7-b0c05698992f.htm
    Is there setting to prefix message length as a Int16 or better VarInt (dynamic 7bit int) instead? If not, do you think it would be easy to change in the code (easy as in not tons of code that implicitly assumes a 4 byte length header)

    4) Does this library provide some sorts of channels, like ReliableOrdered, ReliableSequenced or others?

    5) Any plans to implement some pooling? There are huge non-pooled allocations everywhere (like this one or this one here)

    Also, from what I can see DarkRift is trying to be more of a package that does all kinds of additional things, while Hazel is more of a low-level thing, is that fair to say?
     
    Last edited: Jun 29, 2018
  49. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    1,102
    Hey!

    1. You are correct, Hazel has no serializer so only deals with already serialized byte arrays.

    2. Hazel has fragmentation on both TCP and UDP (TCP by default, UDP only with SendOption.FragmentedReliable on the message). You might notice some differences when switching between them but only that one or the other takes more packets etc. Hazel will never hand you incomplete data so you will only ever get whole messages, reassembled already.

    3. The information on the TCP page is correct, the UDP one seems to be missing fragmentation but is otherwise right. It's not too hard to change any details for TCP (including number of bytes for length) but changing UDP is a bit complicated, just because there's a lot more complicated code in there!

    4. Not really, Hazel leaves that up to you in whatever steps you do to create the byte array.

    5. You are right, there are some horrendous allocations in there! I don't really do that much on Hazel anymore because DarkRift takes most of my dev time so it's unlikely I will add pooling at any point. That said, I'm still happy to merge any pull requests if they come through, so if you do make any improvements I'll happily add them.

    Definitely a fair thing to say, although DarkRift is still low level for a networking solution. A good comparison is that Hazel is a networking library and DarkRift is a networking solution.

    Hope that helps,

    Jamie
     
  50. BigToe

    BigToe

    Joined:
    Nov 1, 2010
    Posts:
    208
    I wanted to check if Hazel is expected to be able to run in the Mac OS X editor? I connects to and runs it fine in my windows editor. But when I try to run on the mac, it immediately locks up Unity and I have to force quit. If I use 127.0.0.1 on the mac it will at least call connect() without crashing, but the server is running on my in Parallels...So when I enter in the IP for the virtual machine, or any other IP besides the local IP Unity crashes immediately.

    So I am just trying to figure out if it is supposed to be able to work, or if I didn't build the library correctly or missed a step.

    Thanks!