Example #1
0
//Listen for incoming connections
int gsc::tcp::host_loop(void * data) {
	Host * parent = (Host *) data; Client * temp;
	TCPsocket newConnection;

	while (parent->get_flags() & IS_ACTIVE) {
		//Accept any new connections
		if ((newConnection = SDLNet_TCP_Accept(parent->get_socket()))) {
			//Call the new client function and send the connection info
			temp = new Client(newConnection, parent);
			parent->add_client(temp);

			//Create our new client thread
			if (!(temp->set_thread(SDL_CreateThread((int (*)(void *))client_begin, temp))))
				thread_error();
		}

		SDL_Delay(parent->get_sleep_delay());
	}
	return 0;
}