So the program (on both computers) will runCallbacks on every frame (locked on 60 fps)
public void Update()
{
SteamAPI.RunCallbacks();
}
initialize relay (on program start)
SteamNetworkingUtils.InitRelayNetworkAccess();
create listen socket (after a button is pressed)
listenSocket = SteamNetworkingSockets.CreateListenSocketP2P(0, 0, null);
and will try to connect to the second computer (after a button is pressed)
SteamNetworkingIdentity identityRemote = new SteamNetworkingIdentity();
if (SteamUser.GetSteamID() == new CSteamID(*"mySteamID"*))
identityRemote.SetSteamID64(*"anotherSteamID"*);
else
identityRemote.SetSteamID64(*"mySteamID"*);
connectionSocket = SteamNetworkingSockets.ConnectP2P(ref identityRemote, 0, 0, null);
and the second computer notices that the first computer is trying to connect to him and it will try to connect to the first one, and immediately when the connection state changes they will accept the connection (repeatedly until the state changes again)
if (connectionState == ESteamNetworkingConnectionState.k_ESteamNetworkingConnectionState_Connecting)
{
SteamNetworkingSockets.AcceptConnection(connectionSocket);
}
but for some reason they won't connect and after a while the ESteamNetworkingConnectionState will go into k_ESteamNetworkingConnectionState_ProblemDetectedLocally which what I know is that it timed out
For the last 3 days I've been trying to figure out why they won't connect to each other, I've read the documantation for Steamworks many times, I've searched for this problem but I haven't seen any solution, I tried to go through sample projects to see what am I doing wrong but I haven't got anything from it, I even tried Facepunch.Steamworks but I got so used to Steamworks.NET that Facepunch.Steamworks doesn't make sense to me (which makes sense when Steamworks.NET is trying to be as close to Steamworks and Facepunch.Steamworks is making it from a different stand point).
Does anyone know what can I do to fix this problem ? Is there something that I'm missing ? I would really appreciate it.
PS: If more code is needed then I will provide.
I literally signed up just to help answer your question because the ISteamNetworkingSockets API struggle is real and the documentation is good but not great.
Please note I am using Godot instead of MonoGame but the implementation should be similar for P2P sockets.
Like you, I originally thought the host/server creates a "createListenSocketP2P" and each peer connecting should be using "connectP2P" to connect to the host's "createListenSocketP2P". After a lot (seriously a lot) of trail and error, what worked for me was to create both "createListenSocketP2P" and "connectP2P" for everyone including the host. Let me explain a bit better...
So you have the "call_back()", "InitRelayNetworkAccess()", and "AcceptConnection" setup the same as me. However in my game I also am using Steam's API to create my multiplayer lobby and when players join the lobby I have a method (called "createSocket") that uses the Steam API calls below in following order:
As mentioned above I have every player (including the host/you) inside a lobby array that has their steam names and ids. Then using a loop I run my "createSocket" method above for each player (including the host/you) and it creates all the CSteamID and P2P steam sockets and I can see everyone connected in my program's output console.
The "connectP2P" will fire the callback "AcceptConnection(connectionSocket)" and just like you have it should accept the connection.
I included the "handle" variable just incase. I add the "handle" to a global variable so I can use it later for when I want to call "SendMessageToConnection()" <-- it will want the handle of the user/player you want to send data to.
I hope this helps you or at least guides you to the right answer. Good luck.