Repository navigation
ListenForPunches issue VS ListenForSinglePunch working #5
Copy link
Copy link
Open
Description
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");
}
}
}`
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
TwoTenPvP commentedon Nov 29, 2020
Internally, the code is very similar. The only difference is whether this or this line executes. Are you able to run a debugger or add some print statements to those lines to see what is being ran?
Kreshi commentedon Nov 29, 2020
The lines are identical yes. I debugged the code for a while. In the video there are debugging messages which state that the punch-through actually was successfull on the host as well as on the client (check this out: https://drive.google.com/file/d/1v1u0PjrMvHSTrymUDXW2WmNpMKE05ayE/view?usp=sharing) --> something else must be blocking the client from connecting / host from firing an onconnected event.
some more information on this issue:
To summerize: punch-through gives success-callback on both, host and client, however no connection is established afterwards.
NoserverStudios commentedon Dec 8, 2020
Hey @TwoTenPvP and @Kreshi,
we tried to implement your Puncher-Module into our game but like @Kreshi mentioned the Method "ListenForPunches" not work at all and the function "ListenForSinglePunch" only works for first user joined game.
Where could we download an working NAT punch example project if exists?
Thanks
NoserverStudios
Kreshi commentedon Dec 17, 2020
Hey @NoserverStudios
As a work-around you could call the ListenForSinglePunch behaviour again whenever a new player connects to the server (haven't tested it though).
Best Regards,
Kreshi
NoserverStudios commentedon Dec 19, 2020
Hey @Kreshi
thanks for your work-around and reply!
We tried it already (Maybe wrong?) without success:
Best regards and merry christmas,
NoserverStudios
NoserverStudios commentedon Jan 12, 2021
Hey there,
is there any "working" example of this NAT Puncher in multi player environment?
Thanks and best regards,
NoserverStudios