Permalink
Browse files

fixed client and server get address to get bound socket port from net…

…code.io
  • Loading branch information...
gafferongames committed Aug 15, 2017
1 parent ecf7cbd commit f12480e5dad4bb91baf886412fe9ed411a9cae1d
Showing with 30 additions and 3 deletions.
  1. +4 −0 client.cpp
  2. +4 −0 secure_client.cpp
  3. +4 −0 secure_server.cpp
  4. +4 −0 server.cpp
  5. +7 −0 yojimbo.cpp
  6. +7 −3 yojimbo.h
View
@@ -72,6 +72,10 @@ int ClientMain( int argc, char * argv[] )
client.InsecureConnect( privateKey, clientId, serverAddress );
char addressString[256];
client.GetAddress().ToString( addressString, sizeof( addressString ) );
printf( "client address is %s\n", addressString );
const double deltaTime = 0.01f;
signal( SIGINT, interrupt_handler );
View
@@ -95,6 +95,10 @@ int ClientMain( int argc, char * argv[] )
client.Connect( clientId, connectToken );
char addressString[256];
client.GetAddress().ToString( addressString, sizeof( addressString ) );
printf( "client address is %s\n", addressString );
const double deltaTime = 0.1;
signal( SIGINT, interrupt_handler );
View
@@ -57,6 +57,10 @@ int ServerMain()
const double deltaTime = 0.1;
char addressString[256];
server.GetAddress().ToString( addressString, sizeof( addressString ) );
printf( "server address is %s\n", addressString );
signal( SIGINT, interrupt_handler );
while ( !quit )
View
@@ -52,6 +52,10 @@ int ServerMain()
server.Start( MaxClients );
char addressString[256];
server.GetAddress().ToString( addressString, sizeof( addressString ) );
printf( "server address is %s\n", addressString );
const double deltaTime = 0.01f;
signal( SIGINT, interrupt_handler );
View
@@ -3170,6 +3170,7 @@ namespace yojimbo
{
m_clientId = 0;
m_client = NULL;
m_boundAddress = m_address;
}
Client::~Client()
@@ -3366,13 +3367,15 @@ namespace yojimbo
{
netcode_client_state_change_callback( m_client, this, StaticStateChangeCallbackFunction );
netcode_client_send_loopback_packet_callback( m_client, this, StaticSendLoopbackPacketCallbackFunction );
m_boundAddress.SetPort( netcode_client_get_port( m_client ) );
}
}
void Client::DestroyClient()
{
if ( m_client )
{
m_boundAddress = m_address;
netcode_client_destroy( m_client );
m_client = NULL;
}
@@ -3746,6 +3749,7 @@ namespace yojimbo
yojimbo_assert( KeyBytes == NETCODE_KEY_BYTES );
memcpy( m_privateKey, privateKey, NETCODE_KEY_BYTES );
m_address = address;
m_boundAddress = address;
m_config = config;
m_server = NULL;
}
@@ -3783,12 +3787,15 @@ namespace yojimbo
netcode_server_send_loopback_packet_callback( m_server, this, StaticSendLoopbackPacketCallbackFunction );
netcode_server_start( m_server, maxClients );
m_boundAddress.SetPort( netcode_server_get_port( m_server ) );
}
void Server::Stop()
{
if ( m_server )
{
m_boundAddress = m_address;
netcode_server_stop( m_server );
netcode_server_destroy( m_server );
m_server = NULL;
View
@@ -5334,7 +5334,7 @@ namespace yojimbo
void ProcessLoopbackPacket( int clientIndex, const uint8_t * packetData, int packetBytes, uint64_t packetSequence );
const Address & GetAddress() const { return m_address; }
const Address & GetAddress() const { return m_boundAddress; }
private:
@@ -5352,7 +5352,8 @@ namespace yojimbo
ClientServerConfig m_config;
netcode_server_t * m_server;
Address m_address;
Address m_address; // original address passed to ctor
Address m_boundAddress; // address after socket bind, eg. valid port
uint8_t m_privateKey[KeyBytes];
};
@@ -5752,6 +5753,8 @@ namespace yojimbo
void ProcessLoopbackPacket( const uint8_t * packetData, int packetBytes, uint64_t packetSequence );
const Address & GetAddress() const { return m_boundAddress; }
private:
bool GenerateInsecureConnectToken( uint8_t * connectToken,
@@ -5778,7 +5781,8 @@ namespace yojimbo
ClientServerConfig m_config; ///< Client/server configuration.
netcode_client_t * m_client; ///< netcode.io client data.
Address m_address; ///< The client address.
Address m_address; ///< Original address passed to ctor.
Address m_boundAddress; ///< Address after socket bind, eg. with valid port
uint64_t m_clientId; ///< The globally unique client id (set on each call to connect)
};

0 comments on commit f12480e

Please sign in to comment.