Ejemplo n.º 1
0
NetConnection* NetworkSession::FindConnectionInMap(std::string& addrName, const std::string& portName, const Byte& connIndex){
	NetAddresses netAddressesToConnect;
	AllocAddressesForHost(netAddressesToConnect, addrName, portName);
	if (netAddressesToConnect.empty())
		return NULL;

	return FindConnectionInMap(netAddressesToConnect[0], connIndex);

}
Ejemplo n.º 2
0
//-------------------------------------------------------------------------------------------------------
static SOCKET BindAddress( char const *ip, char const *port, int family = AF_UNSPEC, int type = SOCK_STREAM )
{
   SOCKET host_sock = INVALID_SOCKET;

   addrinfo *addr = AllocAddressesForHost( ip, port, family, type, true ); 
   ForEachAddress( addr, TryToBind, &host_sock );
   FreeAddresses(addr);

   return host_sock;
}
Ejemplo n.º 3
0
//-------------------------------------------------------------------------------------------------------
static void NetworkClient( char const *target, char const *port, char const *msg )
{
   char const *host_name = AllocLocalHostName();
   SOCKET sock = BindAddress(host_name, gClientPort, AF_INET, SOCK_DGRAM);
   FreeLocalHostName(host_name);

   if (sock == INVALID_SOCKET) {
      printf( "Could not bind adddress.\n" );
      return;
   }
   
   SpamHelper helper;
   helper.sock = sock;
   helper.msg = msg;

   addrinfo *spam = AllocAddressesForHost( target, port, AF_UNSPEC, SOCK_DGRAM, false );
   ForEachAddress( spam, SpamMessage, &helper ); 
   FreeAddresses( spam );
   
   closesocket( sock );
}
Ejemplo n.º 4
0
NetConnection* NetworkSession::AddConnectionToSelf(const Byte& connIndex, const std::string& connPortService ) {

	static const std::string selfConnName = "self";

	NetAddresses netAddressesToConnect;
	std::string localHostName = AllocLocalHostName();
	AllocAddressesForHost(netAddressesToConnect, localHostName, connPortService );

	std::string addConnDebugToConsole = "Adding Connection to Self";

	AddConnection(netAddressesToConnect[0], connIndex, selfConnName);

	m_netConnNameRegistry[connIndex] = "self";

	addConnDebugToConsole += "\nAdded Connection to Self:" + netAddressesToConnect[0].ToString();

	OUTPUT_STRING_TO_CONSOLE(addConnDebugToConsole, 1000);
	ConsolePrintString(addConnDebugToConsole);

	
	return  m_netConnectionMap[selfConnName];


}
Ejemplo n.º 5
0
//-------------------------------------------------------------------------------------------------------
// This method of looping through addresses is going to be important for both
// hosting and connection. 
static void ListAddressesForHost( char const *host_name, char const *service )
{
   addrinfo *addr = AllocAddressesForHost( host_name, service, AF_UNSPEC, SOCK_STREAM, true );
   ForEachAddress( addr, PrintAddress, nullptr );
   freeaddrinfo(addr);
}