I am digging for 3 days on how to create a dedicated server for Unity games. I have tried SmartFox but seems to complex for what I want and I thought that I can don that in Raknet directly.
All I want is to have a number of RPC registered in server and also in Clients, and call them through the server. So when from a Client I will call “X” RPC it will be invoked in the server and on all other clients, except the caller.
I have tried studding “MasterServer” concept (Nothing helpful - except that I see a connection.
I have tried from RAKNET downloaded samples and compiled the RPC examples, but in this case the UNITY clients don’t connect.
Hi,
a Master Server is usually for finding other game servers on the net, so you can skip this at the moment.
If you are using pure RakNet on the server side, you should use pure RakNet on the client side , too. (Though I don’t know via .dll or the c# port somewhere).
If you want to use built in Unity networking, you might take a look at the network examples in the resource section.
Sending RPCs via Unitys built in network stuff is rather easy to implement.
I agree and know that Master Server is not for dedicated server, but was a point of inspiration (I hoped so).
And about sending RPC via Unity I used them and worked very nice. The issue is that I need to build a more reliable server, than building a unity app as server. And I looked for raknet samples that will cope with unity.
Another solution for me would be to build my own server with my own network layer. But I can’t find anywhere the protocol that Unity is using for networking. And by that I mean not only how datagrams are composed but what is the flow of a connection. Like in FTP (who opens conection, what reply is expected, what should then be sent and so on).
Well downloading raknet directly won’t work with unity. They have a custom build based on an older version. Second, you need to program in Xcode and c++ or make a build that compiles on both. You also will need to structure your own masterserver around what ever version of raknet you choose to use. Of course this is only the begining.
Hi zumwalt, can you please help us, and provide the link where we can find the older version of racknet that works with unity, and maybe some samples how to add on it. I saw your posts around this forum and I saw you might have the most experience with it.
Currently I am not interested in building a Master Server, but just to get into the networking (the dedicate server side)
Thanks.
PS: I will send you some beer in exchange of information
Sure, let me break out my MacBook pro and grab the only know build that works with Unity’s calls. I should have the XCode Carbon Bundle code for building up the library and I think I built it also for VS 2003 on that same machine, once I grab that and post it, I’ll go back and look through Jenkins archives for the original beta source.
EDIT:
Ok here is a simple XCode Project with the correct version of RakNet to get you started, just unzip it, open the project, click on build/go and then open up the Console window so you can visually see the connection. I’ll post some screen shots of information in a minute, but this is to simple, the key will be for you to translate their enumeration for the packets then decipher the rpc elements. All I have dug out of them so far is the enumerators, I haven’t received any information from them about the serialized class that they are using to pass across the information to the server that is then passed around to the clients. That is uber top secret material. You will have to buy the source of Unity to get that uber material. All hush hush internal stuff.
This will, however, let you use their Network.Connect and send, so enjoy.
Oxl, yes, I have done a C# port of RakNet however it won’t work with Unity, and I haven’t heard back from the wonderful individual I was working on, last I heard from him was well over a month ago. He did an awesome job keeping me in the loop on working through a crash issue, then he got uber busy internally and had passed it on to another tech, but it literally died at that point, with him busy and the tech non-responsive, I just take it that they are fully concentrating on 2.6 and will get back with me after it is released, that or it really has died.
Anyway, for this to work, after you click on build/go, you simply create a C# script file in Unity, call it what ever you want, add it to an ego, and click play, watch the XCode console to see the physical connection happen. The rest is an open book.
using UnityEngine;
using System.Collections;
public class TestConnector : MonoBehaviour {
// Use this for initialization
void Start () {
Network.Connect("127.0.0.1",10000);
}
// Update is called once per frame
void Update () {
}
}
FYI, I have this also working in a cluster, I have only tested 2 remote servers, one in France, one in Italy then with 3 local servers including code that has multiple connections from one client to multiple servers and multiple clients across servers talking to multiple clients, it all works, but this is the bare bone skeleton, not the aforementioned changes.
And here is the screen print of what you should see on the console when you run it, you will see that ID_NEW_INCOMMING_CONNECTION followed by a K. The K came from Unity during the call to connect, that is what was in the packet. FYI you will need to use RakNet for the send and receive, until they add or IF they add in the pass through I requested in the “wish list” to allow us to send custom packets back to have them be handled, I use my own interface using this skeleton framework as it is. Otherwise you will see the error which is image number 2.
I have actually offered to help them with this on many levels, but the “thanks but no thanks, we got this covered and nailed” was the response I got shrugs look through the wish list and vote on my networking wishes
Thanks for all the information gathered in one point, so what I understood from you is that Unity have it’s own add-on on the raknet layer, so anything that we would try to do we would need those “secret” information. All clear for me. So for now I will try a different approach.
Does anyone knows if i use RPC connection from Unity-Unity and the server would contain no objects just the scripts for server and the update would be occasional, would still the server be limited to somewhere 32 connections?
Highly doubtful. The less information you are planning to send between the clients, the more connections you can support. The default server startup has 1000 connections defined, you can change this value when you start the server. The formula is really straight forward to figure out your load.
Logic:
< 32 players, lots of info
32 players, limit info as much as possible
Keep player count max to 64
Another way to look at it:
<32 players, prediction should be ok at a low number in time
32 players <64 players, prediction should be set to a higher number in time because of delays and packet loss increases
scratches head
Ok, so get this, I was tinkering more with my wrapper trying to get more speed out of it and trying to do some packet tracking with it last night until about 3am (wife didn’t like me much, lying in bed with MacBook Pro chugging on C++ RakNet 3.7 code) When it suddenly dawned on me, why deal with wrapping this thing up since Raknet is unmanaged library anyway.
And I was thinking more of your issue and trying to find a cleaner way to handle this which gives more power to C# that what it currently has, which would then also allow the latest and greatest version of RakNet to be usable with Unity. I am not one for having to re-invent the wheel on every new release (and obviously neither is Unity since the core is based on 3.0beta)
So after only 3 hours sleep, and now going on 2 days working on this, I was able to switch Raknet 3.7 to a managed C++ library and static library, the static won’t be of any use without a wrapper, but the dll… well, all of the core changes I made allowed me to do something I wasn’t sure was possible without pinvoking or marshalling, I was able to simply add a reference to the managed debug library… see image below:
(yes, this is a managed C++ library of RakNet 3.7 in VS 2005 C# windows forms project without a wrapper or using dllimport)
Nice for keeping the discussion open, I would really like to get this topic on a permanent going, on how you and maybe me and other can develop a possibility to implement a dedicated server for Unity.
So if I got this right you managed to gather the Raknet into a library that can be used when developing server application?
Question? Have you ever tried to use a Network sniffer to dig the UDP data grams between two Unity (Server / Client). Because I’ve seen that there are specs on Raknet page for the data gram structure.
Not yet, I have been using WireShark to help with packet identification / assembly / disassembly, trying to figure out the datastructure use so that I can come up with a structure that matches theirs without having to keep bugging them for the integration. One thing you have to keep in mind is that they have some sort of generalized serializer that takes any object and serializes it, then send it as a bitstream on a broadcast channel. The channels seem to only be limited to what player ID’s match that channel, so that your broadcast only goes to people within the same range. (probably not explaining that right, everyone around here absolutely knows I can’t explain things right, I just know how to ‘do’ things right)
I’ll have another screen shot to post here in a little bit, I’ll keep it in this thread so that since it is all specific to what you are wanting to do with a stand alone raknet server and Unity using native raknet with built in Unity, that is the goal. The problem, as some know and some don’t, Jenkins changes the packet structure from major release to major release (well .X is major) so 3.0beta was not compatible with 3.1, etc, like 3.5 isn’t compatible with 3.7.
My thought is, if I can keep outside of the “box” of packet issues, all I have to do is deal with the serialization routine and the RPC structure in the code, going through every release to see what has changed on the BYTE level, thats all that matters to me. In about 30 minutes or less I will post a new shot showing the manifest of public methods showing in the browser tree in C# object browser, this is getting mighty interesting on my machine right now.
Hi looking forward for your research (tomorrow) sleep required. Currently I am working on releasing a Iphone App, but after that I will do some Network Sniffing and digging for the protocol.
The idea is that if you know what you are sending and what you are receiving, you can ignore the data layer for now, and just figure out the protocol and logistics flow. Because I guess when logging into a server and call a RPC function, there are some flags sent and received before sending serialized data. And serialization what I know is done in the same way in all languages.
My original was a port using SWIG based on the 3.0beta build, but for some reason Unity crashes hard against that c# library build, not sure why. I have about 200 more files go comb through right now so the entire conversion process will take me a few more hours, going to take a break here in about an hour. All that matters is the bitstream information and the serializer. Even if I never figure out their structure, it will be fine since this new library will be a managed library and I am presuming right now based on current testing that this should work on both Unity Pro and Unity Indy without the need for the C++ piece at all. Once I am done with the conversion, I’ll post a link to the built debug version of the library so that someone with Indy can test it. I’ll even put up a Unity Package that can be used as the client and a C# project that can be used as the server.
The key element here is “if” this works with Mono, which so far I don’t see why not, mono works fine with managed assemblies, it is the unmanaged ones it has issues with. I’ll edit this post when my machine gets through compiling this lastest build with that screen shot I promised.
Edit: as promised, current screen shot of making the classes public in the managed version of the C++ build. Once I get through all of the base classes, I am going to expose all of the structures that are needed and figure out how to expose the templates.
Just tested the incomplete port managed C++ library built in VS 2005 c# within Parallels, copied the DLL to the project on my MacBook Pro under the Assets folder directly, Unity had no errors on the import, then I added a using statement to the top of one of my CS files to see if Unity would puke or not, no errors, so I consider this first step a successful step. At least Unity 2.5 on Snow Leopard, MacBook Pro doesn’t crap out like the SWIG version did. Going to see what it will take to start up the client connector using this new library with regular calls and no dllimport commands. Will post a shot of that hopefully tomorrow. Taking a break from this.
All classes in headers are now exposed, now I am working on the hard part, or trying to figure it out for it to work correctly, getting the inner methods exposed per class that is public and getting all structures exposed so that they can be created via C# by simple “new” commands… here is a short list of exposed classes. Not sure at the moment how to proceed on this next part, doing research now.
Sorry about no recent post on this thread, life and all, but at the moment, I am still trying to optimize the internal methods and the calls to the garbage collector. Straight up, Rakknet shift to managed from unmanaged poses some challenges, class definitions can be shifted from private to public and from unmanaged classes to managed classes, but you can’t simply add the garbage collector directive to the classes, that said, this lead to a new path of development in the core code for me, one that lead down the path of adding additional new classes that handle the garbage collection and create pointers to the correct methods and structures. Not fun especially since my developement team consists of just myself and my Chihuahua and as you can imagine, a small hyper dog doesn’t typically get much coding done but does a great job at grabbing the mouse and running until the chord tightens and snaps back.
This project is going to turn into a pointer reference nightmare, but as long as the pointers do not get garbage collected or go out of scope, this should work out just fine.