How to assign port/ip for receiving?
lolriven opened this issue · 0 comments
lolriven commented
I'm trying to utilise ReceiveMessagesOnChannel but my callbacks aren't receiving anything and I'm not sure if I'm assigning the port correctly, I'm also unaware if the IP is set to localhost by default.
Any ideas?
#include <iostream>
#include <steam/isteamnetworkingmessages.h>
#include <steam/steamnetworkingtypes.h>
#include <steam/steamnetworkingsockets.h>
#include <steam/isteamnetworkingutils.h>
#include <thread>
#include <chrono>
void Callback(SteamNetworkingMessagesSessionRequest_t* messagerequest)
{
fprintf(stderr,"we got a request!\n",0);
}
class Client
{
public:
Client()
{
if(SteamNetworkingUtils()->SetGlobalCallback_MessagesSessionRequest(Callback))
{
if(SteamNetworkingUtils()->SetGlobalConfigValueInt32(k_ESteamNetworkingConfig_LocalVirtualPort,8888))
{
fprintf(stderr,"callback and port assigned\n");
}
}
}
void Run()
{
while(true)
{
SteamNetworkingSockets()->RunCallbacks();
SteamNetworkingMessage_t* pMsg = nullptr;
int count = SteamNetworkingMessages()->ReceiveMessagesOnChannel(0,&pMsg,1);
if(count > 0)
{
fprintf(stderr,"we got a message!\n");
}
std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
}
}
};
int main()
{
SteamDatagramErrMsg errMsg;
if ( !GameNetworkingSockets_Init( nullptr, errMsg ) )
{
fprintf(stderr,"Couldn't init networking sockets\n");
exit(0);
}
SteamNetworkingUtils()->InitRelayNetworkAccess();
Client().Run();
return 0;
}