Hi.
Is it ok to use any port number, Dumb ass me set my server to listen on port 7777
and only assigned port 7777 to the router, thats ok the clients can connect to it but then the clients can't create a room on the server
if it uses port 7777 to create a new room all net work messages just go to the server.
Help from google say's user should use ports from 49152 to 65535 doe this matter.???
So I came up with this class to reuse ports
.
//-----------------------------------------------------------------------------------------------
//this class will hold our available port number
//we can't assign the same port to a room that is all ready in proccess
//using ranges from 49152 to 65535
//------------------------------------------------------------------------------------------------
class cAvailablePorts
{
public:
cAvailablePorts()
{
int32_t startrange = 49152;
while(startrange < 65535)
{
PortNumbers[startrange] = false;//a free port
startrange++;
}
}
~cAvailablePorts(){}
//--------------------------------------------------------------------
//returns a port if -1 then there is no ports left to create a room
//--------------------------------------------------------------------
int32_t GetPort()
{
//we need find the room the client is in and delete it as well
for(PortNumbersIT = PortNumbers.begin(); PortNumbersIT != PortNumbers.end(); ++PortNumbersIT)
{
if(PortNumbersIT->second == false)
{
PortNumbersIT->second = true;//set in use
return PortNumbersIT->first;
}
}
return -1;//error we must have some good game hehehe
}//end getport
///////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------
//when we close a room we need to reclaim the port
//----------------------------------------------------------------------
void RecliamPort(int32_t port)
{
PortNumbersIT = PortNumbers.find(port);
if(PortNumbersIT != PortNumbers.end())
{
PortNumbersIT->second = false;//flag as not used
}
}//end RecliamPort
////////////////////////////////////////////////////////////////////////
//holds our port and a flag if in use
std::unordered_map<int32_t, bool> PortNumbers;
std::unordered_map<int32_t, bool>::iterator PortNumbersIT;
};//end class cAvailablePorts
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
That assigns ports to clients rooms they create on the server. Each room needs its own port.
But now comes the router issue I've now assigned port ranges from 7777 to 65535.
should I just move the server port to 49152 and start the reuse ports from 49153 to 65535.
or is it ok to leave it. Whats the correct practise.
I have it on line if anyone would like to test it. I'm hosting it on my lap top with a dns from noIP.com works great.