I apologize for puting this in a unity 3d forum but RakNet’s forums are dead as hell and need some help with RakNet through C#. I have the dll and the .cs files that were generated by swig, but as there are no documentation using C# its kinda hard to get started with, so if anyone has experience with this please repond to this thread or send me a pm.
I am working on a project with this setup, what’s your question?
Anyone else out there running RakNet 4 c# swig build with Unity? Could really use some help with questions of my own.
Have you had any problems with your client not connecting to your server app? I have tryed the ip of this computer and the “127” ip but no connection. Also could you put the C# interface files that link to the dll in its own dll and copy both? I also wanted to find someone that I could contact in the event that I needed help because the RakNet forums have proven quite useless. I updated this post with the code for both apps, and am doing this to ensure client side functions are working prior to implementing in Unity. As I stated this is the only other place I know to turn to, and apologize if the code blocks do not function right in this post.
client
static void Main(string[] args)
{
if (!File.Exists("RakNet.dll"))
{
Console.WriteLine("The SWIG build of the DLL has not been copied to the executable directory\nCopy from Swig/SwigWindowsCSharpSample/SwigTestApp/bin/X86/Debug/RakNet.dll to\nSwigWindowsCSharpSample/SwigTestApp/bin/Debug/RakNet.dll\nPress enter to quit.");
Console.Read();
return;
}
try
{
RakString dllCallTest = new RakString();
}
catch (Exception e)
{
Console.WriteLine("DLL issue\nAdd SwigOutput/CplusDLLIncludes/RakNetWrap.cxx to the project\nDLL_Swig/RakNet.sln and rebuild.\nPress enter to quit.");
Console.Read();
return;
}
RakPeerInterface clientPeer = RakPeer.GetInstance();
clientPeer.Startup(1, new SocketDescriptor(6000, "127.0.0.1"), 1);
clientPeer.Connect("127.0.0.1", (ushort)6000, "", 0);
if (clientPeer.GetConnectionState(new AddressOrGUID(new SystemAddress("127.0.0.1", 6000))) == ConnectionState.IS_CONNECTED)
{
Console.WriteLine("client connected");
}
clientPeer.CloseConnection(clientPeer.GetSystemAddressFromIndex(0),false);
RakPeer.DestroyInstance(clientPeer);
Console.ReadLine();
}
server
static void Main(string[] args)
{
if (!File.Exists("RakNet.dll"))
{
Console.WriteLine("The SWIG build of the DLL has not been copied to the executable directory\nCopy from Swig/SwigWindowsCSharpSample/SwigTestApp/bin/X86/Debug/RakNet.dll to\nSwigWindowsCSharpSample/SwigTestApp/bin/Debug/RakNet.dll\nPress enter to quit.");
Console.Read();
return;
}
try
{
RakString dllCallTest = new RakString();
}
catch (Exception e)
{
Console.WriteLine("DLL issue\nAdd SwigOutput/CplusDLLIncludes/RakNetWrap.cxx to the project\nDLL_Swig/RakNet.sln and rebuild.\nPress enter to quit.");
Console.Read();
return;
}
RakPeerInterface serverPeer = RakPeer.GetInstance();
serverPeer.Startup(1, new SocketDescriptor(6000, "127.0.0.1"),1);
serverPeer.SetMaximumIncomingConnections(1);
Console.WriteLine("Server started" + serverPeer.GetMyBoundAddress());
Console.ReadLine();
RakPeer.DestroyInstance(serverPeer);
}
Update when I cycle to debug the client app a second time it prints connected. How long should local connections take, and is there a way to speed things up?
Actualy now both apps are working as far as I can tell. However when I close the connection on the client, and re-open it the connection just stays pending as far as I can tell. I have it runing through a while loop so I can keep an eye on the connection state. Once I close the app just like i would and reopen it then it goes through pending-conecting- then it shows the client connected. Is this common for UDP networking or is it a problem with my code and how I am handling things.