Existing RakNet server programmed for MMO, Unity integration possible??

I have been working on an MMO with a couple people for about 4 years, we are probably 1/4 through the creation of it. The server has a ton of functionality but we want to replace the current DarkGDK client with Unity if possible for graphics and ease of use etc… etc…

I used RakNet with c++ to program the server and client. Is it possible for Unity to communicate with my existing RakNet server? I use bitstreams to do all communications in the game currently.

If anyone has more insight into this or documentation on it I would really appreciate it!

Thanks

You can use self-written libraries in Unity, however for unmanaged code you would need Unity Pro.
So either you buy pro or write a managed library on top of your already made c++ one.

(Not 100% sure but i think it didnt change)

This wouldn’t be integrated into unity, I would just need the Unity game clients to accept and parse my network messages from my standalone c++ server and, of course, send messages back to it. Since they both run RakNet, shouldn’t this be possible?

Unity uses RakNet for their networking but they dont provide access to raknets api. Its basically an overlay.
If you want your clients to communicate with you raknet server you would need to use raknets or your own client library.

SO! I bit the bullet and decided to create RakNet 4 DLL from the RakNet Swig files. It works great, took a very long time and lots of work to get it going, but finally did. Below is the link I followed to create the DLL and get me on my way to integration. I am posting the link below and also the full text in case the link gets destroyed in the future for whatever reason.

Thanks to the author.

Just a note, make sure you put the RakNet.dll in the root of your project directory as well as the assets folder!!

http://txcom2003.wordpress.com/2011/05/29/unity-3d-and-raknet-4/

Several days ago I tried to Connect Unity 3 (Client) and RakNet 3.731 (Server) for my research project. When I read the server log, there is some message ID that was send by Client, that was not recognized by Server. ID “131″, I couldn’t find it in the RakNet Library Code. Maybe something has change in the Unity’s RakNet (that’s what I thought). then I tried to find a way how to make the server and the client can use the same RakNet Library. There is away to do that, but I need Unity Pro in order to load RakNet Library that is coded in C++.

I didn’t satisfy with that way, so i tried to find other solution. yeah with unity regular I still can load C# dll. With “Swig”, I can generate C# dll from c++ project. that’s amazing ^^. So this is the way :

For Client Side (Windows):

Download Unity 3, RakNet 4, Swig
Generate the Swig files
Open the windows terminal
Go to RakNet Swig directory
cd C:\RakNetDirectory\DependentExtensions\Swig
execute swig command (I followed this turorial)
C:\Swig\swig.exe -c++ -csharp -namespace RakNet -I”PATH_TO_RAKNETSOURCE” -I”SwigInterfaceFiles” -outdir SwigOutput\SwigCSharpOutput -o SwigOutput\CplusDLLIncludes\RakNet_wrap.cxx SwigInterfaceFiles\RakNet.i
“PATH_TO_RAKNETSOURCE” is the source code directory of raknet (c++ code)
That command will generate c# code and RakNet_wrap.cxx that will be needed in the next step
Create the C# DLL. I used Microsoft Visual Studio 2008 Express Edition with Service Pack 1, CodeBlock user maybe will have little problem with “integer data type”.
Create CLR empty project
Import RakNet source files with “Add Existing Items”
Import RakNet_wrap.cxx with “Add Existing Items”
Setting the Project Properties
Common Properties
Target Framework : .NET Framework 2.0
Configuration Properties
General
Configuration Type : Dynamic Library (.dll)
Character Set : Not Set
C/C++
General
Additional Directory : C:\PathToRakNetSource
Preprocessor
Preprocessor Definitions : WIN32;_DEBUG;_RAKNET_DLL
Code Generation : Multi-threaded Debug DLL (/MDd)
Linker
ws2_32.lib $(NOINHERIT)
Build C# DLL
Create Unity Project
Copy DLL and C# files to Unity Project directory
Maybe RakNetListRakNetSmartPtrRakNetSocket.cs need to be remove from project
Load DLL with Unity C# Script
This is Example how to perform connection :
using UnityEngine;
using System;
using System.Collections;
using RakNet;
public class ConnectGUI : MonoBehaviour {
public static string remoteIP = “127.0.0.1″;
RakPeerInterface myClient;
SocketDescriptor scktDist;

void Awake() {
myClient = RakPeerInterface.GetInstance();
scktDist = new SocketDescriptor();
myClient.Startup(1,scktDist,1);
}
void OnGUI(){

// if not yet connected
myClient.Connect(remoteIP, 25000, “”,0);

}
}

btw, the swig RakNet 4 code is all managed code so it can be used with Unity Free.

However, some module is missing in this binding.
For example: ReplicaManager3.