Toemsel / Network

C# Network Library
https://push-force.dev
GNU Lesser General Public License v3.0
355 stars 65 forks source link

Master no bluetooth behind required bug fix commits. #63

Closed asusralis closed 4 years ago

asusralis commented 4 years ago

Hello! I'm using the no bluetooth branch, but I'm getting a "InvokePacketThreadException" disconnection reason that I suspect is explained in issue 54. Is is it possible to update the branch to the latest?

Toemsel commented 4 years ago

Ofc

Toemsel commented 4 years ago

Master without Bluetooth is up2date 7f8b2c010d8515a4590faa6fc43a7dc1da666a81

asusralis commented 4 years ago

Thank you so much!

Toemsel commented 4 years ago

PS: Feel free to create a new ticket if that doesn't solve your problem. "InvokePacketThreadException" occurs usually if there is an issue within your provided delegate.

asusralis commented 4 years ago

I think you're right. I was doing what was explained in #54, but it seems to be something else.

Toemsel commented 4 years ago

Post the delegate you are using

asusralis commented 4 years ago

I'm using a few different delegates. This is all server side. Client makes sure to register Welcome and Message.

Welcome:

        private void OnConnectionEstablished(Connection connection, ConnectionType connectionType)
        {
            connection.RegisterRawDataHandler("Welcome", OnWelcomeMessageReceived);
        }
private void OnWelcomeMessageReceived(RawData data, Connection connection)
        {
            string username = RawDataConverter.ToASCIIString(data);

            // Check if username can connect (if not, disconnect)
            ....

            ConnectionEstablished?.Invoke(this, connection);

            connection.SendRawData("Welcome", _packer.SerializeMessage(ServerReplicator.CreateInitialBundle(controller)));
            connection.RegisterRawDataHandler("Message", OnMessageReceived);
        }

And message:

        private void OnMessageReceived(RawData data, Connection connection)
        {
            PlayerController controller = _connectedConnections[connection];

            Message message = _packer.DeserializeMessage<Message>(data.Data);

            ServerReplicator.ReceiveMessage(message, controller);
        }

The "_packer" uses Ceras, and I'm pretty sure it doesn't work well with threads. I'm not sure if that is a reason why?

Toemsel commented 4 years ago

Continued on https://github.com/Toemsel/Network/issues/64