MLAPI.Puncher
MLAPI.Puncher copied to clipboard
ListenForPunches issue VS ListenForSinglePunch working
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");
}
}
}`
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?
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:
- the same bug also happens when i try to connect a game-build with the unity editor EVEN when i use the "ListenForSinglePunch" method.
- This only happens when the unity editor is running as host and the game-build is running as client.
- The does not happen the other way around (game-build as host, unity editor as client).
- And from game-build to game-build it only happens when the "ListenForPunches" method is used like stated above.
To summerize: punch-through gives success-callback on both, host and client, however no connection is established afterwards.
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
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
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
Hey @Kreshi
thanks for your work-around and reply! We tried it already (Maybe wrong?) without success:
while (true)
{
using (PuncherClient listener = new PuncherClient("someserver.example.com", 6776))
{
listener.ListenForSinglePunch(new IPEndPoint(IPAddress.Any, targetGameServerPort);
}
Thread.Sleep(5000);
}
Best regards and merry christmas, NoserverStudios
Hey there,
is there any "working" example of this NAT Puncher in multi player environment?
Thanks and best regards, NoserverStudios