static boolean NET_SDL_InitClient(void) { int p; //! // @category net // @arg <n> // // Use the specified UDP port for communications, instead of // the default (2342). // p = M_CheckParm("-port"); if (p > 0) port = atoi(myargv[p+1]); SDLNet_Init(); udpsocket = SDLNet_UDP_Open(0); if (udpsocket == NULL) { I_Error("NET_SDL_InitClient: Unable to open a socket!"); } recvpacket = SDLNet_AllocPacket(1500); #ifdef DROP_PACKETS srand(time(NULL)); #endif return true; }
void Platform::init() { m_done = false; if(SDL_Init(SDL_INIT_EVERYTHING)) { LOGE("Unable to initialize SDL"); return; } SDLNet_Init(); m_rootWidget = new UIWidget(); m_rootWidget->setPhantom(true); m_rootWidget->setId("RootWidget"); m_focusWidget = nullptr; m_grabWidget = nullptr; m_hoveredWidget = nullptr; for(uint8_t i = 0; i < 6; i++) { m_mousePressed[i] = false; m_mousePosition[i] = {0, 0}; m_mouseLastPosition[i] = {0, 0}; m_mouseClickPosition[i] = {0, 0}; } m_offsetPosition = {0, 0}; g_core.init(); }
void net_init(void) { if (SDLNet_Init() < 0) { error("Could not initialize SDL Net: %s\n", SDLNet_GetError()); } }
/* Setup TCP Server, and wait for a single * client to connect */ int setup_server(unsigned port) { #if !defined(PSP) && !defined(EMSCRIPTEN) && !defined(DREAMCAST) && !defined(THREE_DS) is_server = 1; log_message(LOG_INFO, "Starting server on port %u\n",port); //SDL_INIT(SDL_INIT_EVERYTHING); SDLNet_Init(); IPaddress ip; SDLNet_ResolveHost(&ip, NULL, port); server = SDLNet_TCP_Open(&ip); log_message(LOG_INFO, "Waiting for client to connect\n"); while (client == NULL) { client = SDLNet_TCP_Accept(server); SDL_Delay(1000); } const char * message = "Welcome to GB server"; SDLNet_TCP_Send(client, message, strlen(message) + 1); log_message(LOG_INFO, "Client successfully connected\n"); socketset = SDLNet_AllocSocketSet(1); SDLNet_TCP_AddSocket(socketset, client); connection_up = 1; return 1; #endif return 0; }
/* Setup TCP Client, and attempt to connect * to the server */ int setup_client(unsigned port) { #if !defined(PSP) && !defined(EMSCRIPTEN) && !defined(DREAMCAST) && !defined(THREE_DS) is_client = 1; log_message(LOG_INFO, "Attempting to connect to server on port %u\n",port); //SDL_INIT(SDL_INIT_EVERYTHING); SDLNet_Init(); IPaddress ip; //TODO, for now always connect to localhost, fix for any specified ip in //the future SDLNet_ResolveHost(&ip, "localhost", port); client = SDLNet_TCP_Open(&ip); socketset = SDLNet_AllocSocketSet(1); char buf[100]; int i = SDLNet_TCP_Recv(client, buf, 100); for (int j = 0; j < i; j++) { printf("%c",buf[j]); } printf("\n"); SDLNet_TCP_AddSocket(socketset, client); connection_up = 1; return 1; #endif return 0; }
void NetworkManager::NetworkClient(char* str) //http://content.gpwiki.org/index.php/SDL:Tutorial:Using_SDL_net <- good code here, adapt messages accordingly { //http://jcatki.no-ip.org:8080/SDL_net/SDL_net.html <- good documentation here IPaddress ip; /* Call this function once client is selected (after accepting a host if that is possible via GUI) */ int len; char buffer[512]; server = false; host=str; //If a GUI - entered host name is possible, add it to the function arguments and set this to it. if (SDLNet_Init() < 0) { fprintf(stderr, "SDLNet_Init: %s\n", SDLNet_GetError()); exit(EXIT_FAILURE); } /* Resolve the host we are connecting to */ if (SDLNet_ResolveHost(&ip, host, 2000) < 0) { fprintf(stderr, "SDLNet_ResolveHost: %s\n", SDLNet_GetError()); exit(EXIT_FAILURE); } /* Open a connection with the IP provided (listen on the host's port) */ if (!(targetSocket = SDLNet_TCP_Open(&ip))) { fprintf(stderr, "SDLNet_TCP_Open: %s\n", SDLNet_GetError()); exit(EXIT_FAILURE); } }
void init(int argc, char *argv[]) { /* interpret command line arguments */ if ( argc < 3 ) throw "Usage: server <config_file> <port> [<log_file>]"; /* local port */ sscanf( argv[2], "%d", &local_port); if ( local_port < 1 ) throw "The port must be an integer larger than 0"; printf( "Starting server on port %d\n", local_port ); srand( (unsigned int)time(NULL) ); /* if ( SDL_Init( SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE ) < 0 ) // |SDL_INIT_VIDEO { printf("Could not initialize SDL: %s.\n", SDL_GetError()); throw "Failed to initialize SDL (SDL_Init)"; }*/ if ( SDLNet_Init() < 0 ) throw "Failed to initialize SDL_net (SDLNet_Init)"; /* initialize server data */ sd = new ServerData( argv[1] ); assert( sd ); sd->log_file = ( argc >= 4 ) ? argv[3] : NULL; sd->wm.generate(); }
bool MainApp::onLoadWorld() { m_pFontTexture = peon::EngineCore::getSingleton().getRenderer()->loadTexture("data\\textures\\font.png"); m_pFont = peon::EngineCore::getSingleton().getRenderer()->loadFont(16, 16, 14); SDLNet_Init(); m_port = 9090; // Resolve the argument into an IPaddress type if(SDLNet_ResolveHost(&m_hostAddress,NULL,m_port)==-1) { return false; } // open the server socket m_hostSocket = SDLNet_TCP_Open(&m_hostAddress); if(!m_hostSocket) { //printf("SDLNet_TCP_Open: %s\n",SDLNet_GetError()); //exit(4); return false; } return true; }
TCPClientSocket::TCPClientSocket(TCPsocket source) { #ifdef NATIVESOCKETS nativetcpstruct=0; #endif sendbuffer=0; isopen = false; if(!SDLNetInited) { if(SDLNet_Init()==-1) { LOG_MSG("SDLNet_Init failed: %s\n", SDLNet_GetError()); return; } SDLNetInited = true; } mysock=0; listensocketset=0; if(source!=0) { mysock = source; listensocketset = SDLNet_AllocSocketSet(1); if(!listensocketset) return; SDLNet_TCP_AddSocket(listensocketset, source); isopen=true; } }
int main(int argc, char **argv) { IPaddress ip; /* Server address */ memset(&state, 0, sizeof(state_t)); state.msg_state = MSG_WRITE; if (SDLNet_Init() < 0) { fprintf(stderr, "SDLNet_Init: %s\n", SDLNet_GetError()); finish(EXIT_FAILURE); } /* Resolve the host we are connecting to */ if (SDLNet_ResolveHost(&ip, "localhost", SOCKK) < 0) { fprintf(stderr, "SDLNet_ResolveHost: %s\n", SDLNet_GetError()); finish(EXIT_FAILURE); } /* Open a connection with the IP provided */ if (!(state.sd = SDLNet_TCP_Open(&ip))) { fprintf(stderr, "SDLNet_TCP_Open: %s\n", SDLNet_GetError()); finish(EXIT_FAILURE); } /* Send messages */ #ifdef __EMSCRIPTEN__ emscripten_set_main_loop(main_loop, 60, 0); #else while (1) main_loop(); #endif return EXIT_SUCCESS; }
int network_init() { int r = SDLNet_Init(); if (r) { std::cerr << "Error initializing network functionality: " << SDLNet_GetError() << "\n"; } return r; }
bool UdpConnection::initSdlNet() { if (SDLNet_Init() == -1) { std::cout << "SDL_Net could not initialize: " << SDLNet_GetError() << std::endl; return false; } return true; }
void initSDL(void){ SDL_Init(SDL_INIT_VIDEO); gWindow = SDL_CreateWindow("Battlecave", SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED, SCREENWIDTH, SCREENHEIGHT, SDL_WINDOW_SHOWN); if(gWindow == NULL){ printf("Window creation failed!\n"); exit(EXIT_FAILURE); } gRenderer = SDL_CreateRenderer(gWindow, -1, SDL_RENDERER_ACCELERATED); if(gRenderer == NULL){ printf("Renderer creation failed!\n"); exit(EXIT_FAILURE); } if(TTF_Init() < 0){ printf("TTF Init failed!\n"); exit(EXIT_FAILURE); } if(SDLNet_Init() < 0){ printf("SDL Net Init failed!\n"); exit(EXIT_FAILURE); } SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF); return; }
void OSystem_SDL::initSDL() { // Check if SDL has not been initialized if (!_initedSDL) { // We always initialize the video subsystem because we will need it to // be initialized before the graphics managers to retrieve the desktop // resolution, for example. WebOS also requires this initialization // or otherwise the application won't start. uint32 sdlFlags = SDL_INIT_VIDEO; if (ConfMan.hasKey("disable_sdl_parachute")) sdlFlags |= SDL_INIT_NOPARACHUTE; // Initialize SDL (SDL Subsystems are initiliazed in the corresponding sdl managers) if (SDL_Init(sdlFlags) == -1) error("Could not initialize SDL: %s", SDL_GetError()); _initedSDL = true; } #ifdef USE_SDL_NET // Check if SDL_net has not been initialized if (!_initedSDLnet) { // Initialize SDL_net if (SDLNet_Init() == -1) error("Could not initialize SDL_net: %s", SDLNet_GetError()); _initedSDLnet = true; } #endif }
void Server::Init() { /* Initialize SDL_net */ if (SDLNet_Init() < 0) { fprintf(stderr, "SDLNet_Init: %s\n", SDLNet_GetError()); exit(EXIT_FAILURE); } /* Open a socket */ if (!(sd = SDLNet_UDP_Open(7777))) { fprintf(stderr, "SDLNet_UDP_Open: %s\n", SDLNet_GetError()); exit(EXIT_FAILURE); } /* Make space for the packet */ if (!(p = SDLNet_AllocPacket(sizeof(Transform)))) { fprintf(stderr, "SDLNet_AllocPacket: %s\n", SDLNet_GetError()); exit(EXIT_FAILURE); } /* Wait for a connection, send data and term */ quit = 0; }
void NetworkManager::NetworkHost(void) //http://content.gpwiki.org/index.php/SDL:Tutorial:Using_SDL_net <- good code here, adapt messages accordingly { //http://jcatki.no-ip.org:8080/SDL_net/SDL_net.html <- good documentation here TCPsocket sd; /* Call this function once Host button is selected */ IPaddress ip; char buffer[512]; server = true; if (SDLNet_Init() < 0) { fprintf(stderr, "SDLNet_Init: %s\n", SDLNet_GetError()); exit(EXIT_FAILURE); } /* Resolving the host using NULL make network interface to listen */ if (SDLNet_ResolveHost(&ip, NULL, 2000) < 0) { fprintf(stderr, "SDLNet_ResolveHost: %s\n", SDLNet_GetError()); exit(EXIT_FAILURE); } /* Open a connection with the IP provided (listen on the host's port) */ if (!(sd = SDLNet_TCP_Open(&ip))) { fprintf(stderr, "SDLNet_TCP_Open: %s\n", SDLNet_GetError()); exit(EXIT_FAILURE); } /* Wait for a connection*/ while (!(targetSocket = SDLNet_TCP_Accept(sd))) { } std::cout<<"accepted client"; }
Core::Core() { SDL_Init(SDL_INIT_EVERYTHING); IMG_Init(IMG_INIT_PNG); TTF_Init(); SDLNet_Init(); Packet * packet = new Packet(); network = new Network(packet); events = new Events(); renderer = new Renderer(); movement = new Movement(); player = new Player(movement, packet); renderer->addPlayer(player); events->addPlayer(player); //renderer->addRenderObject(player->getSs()); //delete packet; network->start(movement, renderer, player); GameVariables::running = true; //TODO: check for successful initialization }
int main(int argc, char* args[]){ //if(SDL_Init(SDL_INIT_TIMER) == -1){ fprintf(stderr,"Could not initialize SDL: %s",SDL_GetError()); exit(EXIT_FAILURE); } if(SDLNet_Init() == -1){ fprintf(stderr,"Could not initialize SDL_net: %s",SDLNet_GetError()); exit(EXIT_FAILURE); } #if defined _WIN32 || defined _WIN64 fclose(stdout); fclose(stderr); fclose(stdin); remove("stdout.txt"); remove("stderr.txt"); freopen( "CON", "w", stdout); freopen( "CON", "w", stderr); freopen( "CON", "r", stdin ); #endif if(!LoggerInit())return EXIT_FAILURE; LoggerPrint("\n ----- G SERVER v%s Protocol %d -----\n\n",GAME_VERSION,PROTOCOL_VERSION); if(!config.Load())return EXIT_FAILURE; Server server; server.Construct(); server.Start(); server.Destruct(); LoggerPrint("Server finished.\n\n"); LoggerExit(); SDLNet_Quit(); //SDL_Quit(); return EXIT_SUCCESS; }
TCPClientSocket::TCPClientSocket(const char* destination, Bit16u port) { #ifdef NATIVESOCKETS nativetcpstruct=0; #endif sendbuffer=0; isopen = false; if(!SDLNetInited) { if(SDLNet_Init()==-1) { LOG_MSG("SDLNet_Init failed: %s\n", SDLNet_GetError()); return; } SDLNetInited = true; } mysock=0; listensocketset=0; IPaddress openip; //Ancient versions of SDL_net had this as char*. People still appear to be using this one. if (!SDLNet_ResolveHost(&openip,const_cast<char*>(destination),port)) { listensocketset = SDLNet_AllocSocketSet(1); if(!listensocketset) return; mysock = SDLNet_TCP_Open(&openip); if(!mysock) return; SDLNet_TCP_AddSocket(listensocketset, mysock); isopen=true; } }
/* * network_init() - Initialize SDL's networking functionality */ int network_init() { int r = SDLNet_Init(); // Attempt to initiliaze networking if (r != 0) { // If an error was returned, print it out std::cerr << "Error initializing network functionality: " << SDLNet_GetError() << "\n"; } return r; // Return the error code }
void Networking::initSDLNet() { if ( SDLNet_Init() < 0 ) { fprintf(stderr, "Couldn't initialize net: %s\n", SDLNet_GetError()); SDL_Quit(); exit(1); } }
bool Client::OnInit() { if ( SDLNet_Init() == -1 ) { cout << "\nSDLNet_Init failed : " << SDLNet_GetError() << endl; return false; } if ( SDL_Init(SDL_INIT_EVERYTHING) == -1) { cout<< "\nSDL_Init failed : " << SDL_GetError() <<endl; return false; } if((Window = SDL_CreateWindow("Client", 300, 300, 640, 480, SDL_WINDOW_SHOWN)) == NULL) { cout<< "\nSDL_CreateWindow failed : " << SDL_GetError() <<endl; return false; } if((Renderer = SDL_CreateRenderer(Window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC)) == NULL) { cout <<"\nSDL_CreateRenderer failed : "<< SDL_GetError() << endl; return false; } if(LoadContent() == false) { cout<< "\nLoadContent failed" <<endl; return false; } return true; }
Net::Net() { // Ensure Core is initialized get_Core(); if(SDLNet_Init()) throw Net_Init_Failure(); }
/* int checkArgs(int args, char** argv){ for (int i = 1; i < args; i++){ if (SDL_strcmp(argv[i], "--autostart") == 0){ if (i < args - 1){ } } else{ mythVirtualSqlite::GetInstance()->SetSQLIP(argv[1]); SDL_Log("sqlip is now changed to %s\n", argv[1]); } } return 0; } */ int main(int args, char** argv) { SDL_Init(SDL_INIT_EVENTS); SDLNet_Init(); mythStreamMapServer* streammapserver = mythStreamMapServer::CreateNew(streamserverport); streammapserver->StartServer(); #ifdef _DEBUG char input[256]; for (;;){ printf(">"); gets(input); if (mythcmp("exit")){ break; } else if (mythcmp("show")){ streammapserver->showAllClients(); } else if (mythcmp("stop")){ streammapserver->StopServer(); } else if (mythcmp("startall")){ streammapserver->startAll(); } else{ system(input); } } #endif streammapserver->StopServer(); delete streammapserver; SDL_Quit(); return 0; }
static boolean NET_SDL_InitServer(void) { int p; if (initted) return true; p = M_CheckParmWithArgs("-port", 1); if (p > 0) port = atoi(myargv[p+1]); SDLNet_Init(); udpsocket = SDLNet_UDP_Open(port); if (udpsocket == NULL) { I_Error("NET_SDL_InitServer: Unable to bind to port %i", port); } recvpacket = SDLNet_AllocPacket(1500); #ifdef DROP_PACKETS srand(time(NULL)); #endif initted = true; return true; }
int eb_open_subsystems(void) { if(SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO #ifndef _WIN32 | SDL_INIT_EVENTTHREAD #endif #ifdef DEBUG | SDL_INIT_NOPARACHUTE #endif ) == 0) { if(FE_Init() == 0) { if(SDLNet_Init() == 0) { if(NET2_Init() == 0) return 0; fprintf(stderr, "EELBox: Could not initialize" " Net2!\n"); SDLNet_Quit(); } fprintf(stderr, "EELBox: Could not initialize" " SDL_net!\n"); FE_Quit(); } fprintf(stderr, "EELBox: Could not initialize FastEvents!\n"); SDL_Quit(); } fprintf(stderr, "EELBox: Could not initialize SDL!\n"); return -1; }
int main(int argc, char **argv) { IPaddress ip; /* Server address */ TCPsocket sd; /* Socket descriptor */ int quit, len; char buffer[512]; /* Simple parameter checking */ if (argc < 3) { fprintf(stderr, "Usage: %s host port\n", argv[0]); exit(EXIT_FAILURE); } if (SDLNet_Init() < 0) { fprintf(stderr, "SDLNet_Init: %s\n", SDLNet_GetError()); exit(EXIT_FAILURE); } /* Resolve the host we are connecting to */ if (SDLNet_ResolveHost(&ip, argv[1], atoi(argv[2])) < 0) { fprintf(stderr, "SDLNet_ResolveHost: %s\n", SDLNet_GetError()); exit(EXIT_FAILURE); } /* Open a connection with the IP provided (listen on the host's port) */ if (!(sd = SDLNet_TCP_Open(&ip))) { fprintf(stderr, "SDLNet_TCP_Open: %s\n", SDLNet_GetError()); exit(EXIT_FAILURE); } /* Send messages */ quit = 0; while (!quit) { printf("Write something:\n>"); scanf("%s", buffer); len = strlen(buffer) + 1; if (SDLNet_TCP_Send(sd, (void *)buffer, len) < len) { fprintf(stderr, "SDLNet_TCP_Send: %s\n", SDLNet_GetError()); exit(EXIT_FAILURE); } if(strcmp(buffer, "exit") == 0) quit = 1; if(strcmp(buffer, "quit") == 0) quit = 1; } SDLNet_TCP_Close(sd); SDLNet_Quit(); return EXIT_SUCCESS; }
void Users::connect(Universe *_u){ u = _u; SDLNet_Init(); SDLNet_ResolveHost(&ip,NULL,port); sock = SDLNet_TCP_Open(&ip); set = SDLNet_AllocSocketSet(10); SDLNet_TCP_AddSocket(set,sock); }
int network_start() { srand(time(0)); if (SDL_Init(SDL_INIT_TIMER)) return 1; if (SDLNet_Init()) return 1; return 0; }
void init_net() { if (SDLNet_Init() < 0) { fprintf(stderr, "SDLNet_Init: %s\n", SDLNet_GetError()); exit(EXIT_FAILURE); } }