Describe the bug
Importing the DLL into Unity creates some issues. Using only the source code results in everything executing fine. I want to support both the DLL and importing the source code. In the DLL... BeginConnect()
does not work as intended. This is when it's ran in Unity via a DLL. When the client is ran via an executable, the command line, or in Visual Studio then it runs fine.
The AsyncCallback
never happens in BeginConnect()
. But it connects! It just doesn't callback for some odd reason. I've asked around and did some research the for about a full day. Not getting very far. This is the last bit to move to the next phase.
You can find information on it here: Client.cs & BaseClient.cs.
BaseClient
contains BeginConnect()
. Client is what contains added functionality. Unity uses Client.
To Reproduce
There are two solutions in the structure branch. One for hosting a server / stress-testing client connections (5000 tested so far). The other for deploying a client only build. If you open SustenetClient.sln and go to the post build script, you can define a project location to automatically output it to. I'll eventually change it to have an option that copies the source code instead of the DLL so compile times are faster.
Steps to reproduce the behavior:
- Go to 'SustenetClient.sln'
- Optional: Go to the post build settings and change the directory to someplace that exists, preferably a test project.
- Build the project, copy the DLL if it wasn't done for you automatically with step 2.
- Declare a
Sustenet.Clients.Client client
and initialize it Start()
.
- In
Update()
call ThreadManager.UpdateMain()
.
Expected behavior
Calling Connect()
should result in ConnectCallback
triggering like it does when a .cs file is used instead of a DLL.
Desktop (please complete the following information):
Additional context
The code below can be used to get a quick setup with the DLL attached, or you can still build your own DLL and use the code as well.
SustenetClient.zip (DLL) ./TestUnityProject/Sustenet/SustenetClient.dll
./TestUnityProject/Sustenet/ClientManager.cs
using UnityEngine;
using UnityEngine.UI;
using Sustenet.Transport;
public class ClientManager : MonoBehaviour
{
public Client client;
public Button btn;
// Start is called before the first frame update
void Start()
{
client = new Client();
btn.onClick.AddListener(() => client.Connect());
}
// Update is called once per frame
void Update()
{
ThreadManager.UpdateMain();
Debug.Log(client);
}
}
./TestUnityProject/Sustenet/Client.cs
using System.Collections.Generic;
using UnityEngine;
using Sustenet.Network;
public class Client : Sustenet.Clients.Client
{
public Client() : base(debug: false) { }
protected override void InitializeClientData()
{
Debug.Log("Initializing...");
tcp.onConnected.Run += () => {
Debug.Log("Successfully connected to the master server.");
};
tcp.onReceived.Run += (data) => {
Debug.Log("Testing onReceived: " + data);
};
tcp.onDebug.Run += (msg) => DebugClient(msg);
tcp.onDebug.RaiseEvent("Testing onDebug");
packetHandlers = new Dictionary<int, PacketHandler>()
{
{ (int)ServerPackets.welcome, this.Welcome }
};
}
protected void DebugClient(string msg)
{
Debug.Log($"Client#{id}: {msg}");
}
}