Skip to content

[Unity] if you exit the program, the port will not close and will be occupied. #29

Discussion options

You must be logged in to vote
Can Netly automatically handle this issue?

No! OnApplicationQuit() => server.Close(); is only available to MonoBehaviour children. The another way is using Application.quitting += server.Close()

The unique good way is editing source code: Netly/src/Udp/UdpServer.cs

UdpServer.cs
namespace Netly
{
    public class UdpServer
    {
        public UdpServer(bool useConnection, int timeout = 10000)
        {
#if UNITY_ENGINE
            UnityEngine.Application.quitting += this.Close();
#endif
        }
    }
}
Netly Code. Easy way
using System;
using Netly;
using Netly.Core;

public class Example: MonoBehaviour
{
    private UdpServer server = new UdpServer();

    private void OnApplicationQuit

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by 1101728133
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers ToDo Extra attention is needed (To Do)
2 participants