Skip to content

ListenForPunches issue VS ListenForSinglePunch working #5

@Kreshi

Description

@Kreshi

Hello,

here the YouTube video describing the issue: https://youtu.be/aHU8hiAHERY
Tested: locally with public IP - MLAPI.Puncher.Server plus the two game instances were all running on the same device simultaneously.
Used code snippets:

`public void ui_setupHostSingle()
{
closeConnection();

    m_listenTask = Task.Factory.StartNew(() =>
    {
        try
        {
            string puncherServerHost = puncherIPAddressInputField.text;
            using (m_listenPeer = new PuncherClient(puncherServerHost, PUNCHER_SERVER_PORT))
            {
                Debug.Log("[LISTENER] Listening for single punch on our port 1234...");
                IPEndPoint endpoint = m_listenPeer.ListenForSinglePunch(new IPEndPoint(IPAddress.Any, GAME_SERVER_PORT));
                Debug.Log("[LISTENER] Connector: " + endpoint + " punched through our NAT");
            }
        }
        catch (Exception e)
        {
            Debug.LogError(e);
        }
    });

    NetworkingManager.Singleton.GetComponent<EnetTransport.EnetTransport>().Port = GAME_SERVER_PORT;
    NetworkingManager.Singleton.ConnectionApprovalCallback += approvalCheck;
    NetworkingManager.Singleton.StartHost();
}

public void ui_setupHostLoop()
{
    closeConnection();

    m_listenTask = Task.Factory.StartNew(() =>
    {
        try
        {
            string puncherServerHost = puncherIPAddressInputField.text;
            using (m_listenPeer = new PuncherClient(puncherServerHost, PUNCHER_SERVER_PORT))
            {
                Debug.Log("[LISTENER] Listening for single punch on our port 1234...");
                m_listenPeer.OnConnectorPunchSuccessful += (endpoint) =>
                {
                    Debug.Log("[LISTENER] Connector: " + endpoint + " punched through our NAT");
                };
                m_listenPeer.ListenForPunches(new IPEndPoint(IPAddress.Any, GAME_SERVER_PORT));
            }
        }
        catch (Exception e)
        {
            Debug.LogError(e);
        }
    });

    NetworkingManager.Singleton.GetComponent<EnetTransport.EnetTransport>().Port = GAME_SERVER_PORT;
    NetworkingManager.Singleton.ConnectionApprovalCallback += approvalCheck;
    NetworkingManager.Singleton.StartHost();
}

public void ui_setupClient()
{
closeConnection();

    string address = connectToIPAddressInputField.text;

    string puncherServerHost = puncherIPAddressInputField.text;
    using (PuncherClient connectPeer = new PuncherClient(puncherServerHost, PUNCHER_SERVER_PORT))
    {
        Debug.Log("[CONNECTOR] Punching...");

        if (connectPeer.TryPunch(IPAddress.Parse(address), out IPEndPoint connectResult))
        {
            Debug.Log("[CONNECTOR] Punched through to peer: " + connectResult);

            NetworkingManager.Singleton.GetComponent<EnetTransport.EnetTransport>().Port = (ushort)connectResult.Port;
            NetworkingManager.Singleton.GetComponent<EnetTransport.EnetTransport>().Address = connectResult.Address.ToString();

            NetworkingManager.Singleton.NetworkConfig.ConnectionData = System.Text.Encoding.ASCII.GetBytes("room password");
            NetworkingManager.Singleton.StartClient();
        }
        else
        {
            Debug.LogError("[CONNECTOR] Failed to punch");
        }
    }

}`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions