Closed oddgames-david closed 9 years ago
The code below definitely fires on both clients but I don't get any messages after that and when I check netPeer.Connections it's still at "1" which is the connection to the master server.
case NetIncomingMessageType.NatIntroductionSuccess:
Debug.Log("Nat: " + msg.SenderEndPoint.ToString() + " : " + this.GetHashCode());
netPeer.Connect(msg.SenderEndPoint);
Debug.Log(netPeer.Connections.Count);
Did you set NetPeerConfiguration.AcceptIncomingConnections to true for each of those peers? I forgot it when I evaluated this library a few days ago :)
Yes, this is my config:
config.PingInterval = 0.5f;
config.ConnectionTimeout = 5;
config.MaximumConnections = 32;
config.AcceptIncomingConnections = true;
config.AutoFlushSendQueue = true;
config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
config.EnableMessageType(NetIncomingMessageType.UnconnectedData);
config.EnableMessageType(NetIncomingMessageType.NatIntroductionSuccess);
I've had it randomly work twice. I get these each time though:
NAT punch received from 127.0.0.1:57754 we're client, so we've succeeded - token is MatchMaking NAT punch received from 192.168.1.2:57754 we're host, so we ignore this
I'm guessing the NAT punch is really successful enough.
I tried the master server sample and it still doesn't make the connection.
m_client.Connections.Count = 0 in the MSCLIENT after a NatIntroductionSuccess
Just to add to this, I'm spawning 2 NetPeers and having them connect to a master server. I'm assuming I can do this and have those two peers make connections to each other.
Any help would be appreciated as I'm still pretty stuck.
I'll can try to run the same example when I'm at home - what's your setup? Are the peers and master server on the same computer or different ones?
All on same PC.
Master seperate process Client both in same process as seperate objects
Ok, I turned off UPnP on my router and now get the error below, what's interesting is that I turned UPnP back on then used DiscoverKnownPeer after a NatIntroductionSuccess message and connected on a DiscoveryResponse message and I get the same message.
I assume this is a good message and it's actually trying to connect but it has issues adding with the m_handshakes collection, adding to it from a different thread or something.
System.InvalidOperationException: out of sync
at System.Collections.Generic.Dictionary2+Enumerator[System.Net.IPEndPoint,Lidgren.Network.NetConnection].VerifyState () [0x00028] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:912 at System.Collections.Generic.Dictionary
2+Enumerator[System.Net.IPEndPoint,Lidgren.Network.NetConnection].MoveNext () [0x00000] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:835
at Lidgren.Network.NetPeer.Heartbeat () [0x000c0] in C:\Users\David\Documents\LidgrenTest\Assets\Lidgren.Network\NetPeer.Internal.cs:322
at Lidgren.Network.NetPeer.NetworkLoop () [0x00000] in C:\Users\David\Documents\LidgrenTest\Assets\Lidgren.Network\NetPeer.Internal.cs:208
UnityEngine.Debug:Log(Object)
Lidgren.MatchMaking.
Ok, I figured out what I was doing wrong.
My master server was trying to Introduce both sides Introduce(A,B) then Introduce(B,A).
And it was also doubling up the introductions. It connects everytime now, sometimes it produces an out of sync error but it still seems to connect the peers successfully.
I've kept the DiscoverKnownPeer as that seems to work when UPnP is enabled or disabled.
Close this issue.
I'm using "Introduce" on a master server that has 2 connected clients.
When I receive "NatIntroductionSuccess" how do I connect to the peer?
using netPeer.Connection(endPoint) doesn't seem to do anything (the connections doesn't increase).