コード例 #1
0
ファイル: psp_network.cpp プロジェクト: Bananattack/verge3
ServerSocket::ServerSocket(int port)
{
    InitializeNetwork();

    // create the socket
    //m_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    //if (m_socket == INVALID_SOCKET) {
    //    throw NetworkException("socket() failed");
    //}

    //// make it nonblocking
    //unsigned long ul = 1;
    //if (ioctlsocket(m_socket, FIONBIO, &ul) != 0) {
    //    closesocket(m_socket);
    //    throw NetworkException("ioctlsocket() failed");
    //}

    //// bind the socket to an address
    //sockaddr_in name;
    //memset(&name, 0, sizeof(name));
    //name.sin_family      = AF_INET;
    //name.sin_addr.s_addr = INADDR_ANY;
    //name.sin_port        = htons(port);
    //if (bind(m_socket, (sockaddr*)&name, sizeof(name)) != 0) {
    //    closesocket(m_socket);
    //    throw NetworkException("bind() failed");
    //}

    //// now listen on it
    //if (listen(m_socket, 1) != 0) {
    //    closesocket(m_socket);
    //    throw NetworkException("listen() failed");
    //}
}
コード例 #2
0
void OnStart()
{
	InitializeNetwork();

	g_ServerStarted = false;
	g_StartedThread = false;
	g_GotSocket     = false;
	g_RunningThread = false;

	g_FrameBuffer = ( unsigned char* )malloc( ImageWidth * ImageHeight * 4 );
	memset( g_FrameBuffer, 0x0, ImageWidth * ImageHeight * 4 );

	// 1. initialize font
	font = read_bmp_mem( font_data, &fw, &fh );

	char_w = fw / 16;
	char_h = fh / 16;

	// 2. detect adapter
	Net_EnumerateAdapters( Adapters );

	// 3. start webserver
	clHTTPServerThread* th = new clHTTPServerThread();

	if ( !Adapters.empty() )
	{
		th->FBindAddress = std::string( Adapters[0].FIP );
	}

	th->Start( iThread::Priority_Normal );
}
コード例 #3
0
ファイル: networkop.cpp プロジェクト: CJB100/fceugc
bool
ConnectShare (bool silent)
{
	if(!InitializeNetwork(silent))
		return false;

	if(networkShareInit)
		return true;

	int retry = 1;
	int chkS = (strlen(GCSettings.smbshare) > 0) ? 0:1;
	int chkI = (strlen(GCSettings.smbip) > 0) ? 0:1;

	// check that all parameters have been set
	if(chkS + chkI > 0)
	{
		if(!silent)
		{
			char msg[50];
			char msg2[100];
			if(chkS + chkI > 1) // more than one thing is wrong
				sprintf(msg, "Check settings.xml.");
			else if(chkS)
				sprintf(msg, "Share name is blank.");
			else if(chkI)
				sprintf(msg, "Share IP is blank.");

			sprintf(msg2, "Invalid network settings - %s", msg);
			ErrorPrompt(msg2);
		}
		return false;
	}

	while(retry)
	{
		if(!silent)
			ShowAction ("Connecting to network share...");
		
		if(smbInit(GCSettings.smbuser, GCSettings.smbpwd, GCSettings.smbshare, GCSettings.smbip))
			networkShareInit = true;

		if(networkShareInit || silent)
			break;

		retry = ErrorPromptRetry("Failed to connect to network share.");
	}

	if(!silent)
		CancelAction();

	return networkShareInit;
}
コード例 #4
0
ファイル: smbop.cpp プロジェクト: feraligatr/vbagx
bool
ConnectShare (bool silent)
{
	// Crashes or stalls system in GameCube mode - so disable
	#ifndef HW_RVL
	return false;
	#endif

	// check that all parameter have been set
	if(strlen(GCSettings.smbuser) == 0 ||
		strlen(GCSettings.smbpwd) == 0 ||
		strlen(GCSettings.smbshare) == 0 ||
		strlen(GCSettings.smbip) == 0)
	{
		if(!silent)
			WaitPrompt((char*) "Invalid network settings. Check SNES9xGX.xml.");
		return false;
	}

	if(!networkInit)
		networkInit = InitializeNetwork(silent);

	if(networkInit)
	{
		// connection may have expired
		if (networkShareInit && SMBTimer > SMBTIMEOUT)
		{
			networkShareInit = false;
			SMBTimer = 0;
			SMB_Close(smbconn);
		}

		if(!networkShareInit)
		{
			if(!silent)
				ShowAction ((char*) "Connecting to network share...");

			if(SMB_Connect(&smbconn, GCSettings.smbuser, GCSettings.smbpwd,
			GCSettings.smbgcid, GCSettings.smbsvid, GCSettings.smbshare, GCSettings.smbip) == SMB_SUCCESS)
				networkShareInit = true;
		}

		if(!networkShareInit && !silent)
			WaitPrompt ((char*) "Failed to connect to network share.");
	}

	return networkShareInit;
}
コード例 #5
0
ファイル: Client.cpp プロジェクト: opatut/chars
void Client::Go() {
    Logger::GetLogger().Info("--- Loading config ---");
    LoadConfig();

    Logger::GetLogger().Info("--- Initializing Network ---");
    if(!InitializeNetwork())
        return;

    Logger::GetLogger().Info("--- Starting render engine ---");
    StartupOgre();

    Logger::GetLogger().Info("--- Starting main loop ---");
    RunLoop();

    Logger::GetLogger().Info("--- Stopping ---");
    Shutdown();
}
コード例 #6
0
int main(int nargs, const char *args[])
{
	InitializeNetwork();

	GameServer GS;
	GS.startServer("wozzy");

	int nPlayers = GS.getNumberOfPlayers();
	while(true)
	{
		if(nPlayers != GS.getNumberOfPlayers())
		{
			nPlayers = GS.getNumberOfPlayers();
			cout << "nPlayers = " << nPlayers << endl;
		}
	}

	ShutdownNetwork();

	return 0;
}
コード例 #7
0
//----------------------------- Train ------------------------------------
//
//  Given some training data in the form of a CData object this function
//  trains the network until the error is within acceptable limits.
// 
//  the HWND is required to give some graphical feedback
//------------------------------------------------------------------------
bool CNeuralNet::Train(CData* data, HWND hwnd)
{
  vector<vector<double> > SetIn  = data->GetInputSet();
  vector<vector<double> > SetOut = data->GetOutputSet();

   //first make sure the training set is valid
   if ((SetIn.size()     != SetOut.size())  || 
       (SetIn[0].size()  != m_iNumInputs)   ||
       (SetOut[0].size() != m_iNumOutputs))
   {
     MessageBox(NULL, "Inputs != Outputs", "Error", NULL);
    
     return false;
   }
  
   //initialize all the weights to small random values
   InitializeNetwork();

   //train using backprop until the SSE is below the user defined
   //threshold
   while( m_dErrorSum > ERROR_THRESHOLD )
   {
     //return false if there are any problems
     if (!NetworkTrainingEpoch(SetIn, SetOut))
     {
       return false;
     }

     ++m_iNumEpochs;
     
     //call the render routine to display the error sum
     InvalidateRect(hwnd, NULL, TRUE);
		 UpdateWindow(hwnd);
   }

   m_bTrained = true;
   
   return true;
}
コード例 #8
0
ファイル: networkop.cpp プロジェクト: feraligatr/vbagx
bool
ConnectShare (bool silent)
{
	// Crashes or stalls system in GameCube mode - so disable
	#ifndef HW_RVL
	return false;
	#endif

	int chkU = (strlen(GCSettings.smbuser) > 0) ? 0:1;
	int chkP = (strlen(GCSettings.smbpwd) > 0) ? 0:1;
	int chkS = (strlen(GCSettings.smbshare) > 0) ? 0:1;
	int chkI = (strlen(GCSettings.smbip) > 0) ? 0:1;

	// check that all parameters have been set
	if(chkU + chkP + chkS + chkI > 0)
	{
		if(!silent)
		{
			char msg[50];
			char msg2[100];
			if(chkU + chkP + chkS + chkI > 1) // more than one thing is wrong
				sprintf(msg, "Check settings.xml.");
			else if(chkU)
				sprintf(msg, "Username is blank.");
			else if(chkP)
				sprintf(msg, "Password is blank.");
			else if(chkS)
				sprintf(msg, "Share name is blank.");
			else if(chkI)
				sprintf(msg, "Share IP is blank.");

			sprintf(msg2, "Invalid network settings - %s", msg);
			WaitPrompt(msg2);
		}
		return false;
	}

	if(!networkInit)
		InitializeNetwork(silent);

	if(networkInit)
	{
		if(unmountRequired[METHOD_SMB])
			CloseShare();

		if(!networkShareInit)
		{
			if(!silent)
				ShowAction ("Connecting to network share...");

			if(smbInit(GCSettings.smbuser, GCSettings.smbpwd,
					GCSettings.smbshare, GCSettings.smbip))
			{
				networkShareInit = true;
			}
		}

		if(!networkShareInit && !silent)
			WaitPrompt ("Failed to connect to network share.");
	}

	return networkShareInit;
}
コード例 #9
0
ファイル: GameServer.cpp プロジェクト: rkolev/diplomna-igra
void GameServer::Run()
{
	XmlParser parser("settings/Players.xml");
	PlayerType playerType = (PlayerType)parser.ReadInt("/PlayerData/PlayerOneType");
	u32 keybinds[4] = { CL_KEY_LEFT, CL_KEY_RIGHT, CL_KEY_UP, CL_KEY_J };

	Initialize();
	InitializeLevel();
	InitializePlayer(playerType, keybinds);
	InitializeNetwork();

	s32 timeElapsedMs, lastTime, currentTime, waitTime;
	currentTime = lastTime = CL_System::get_time();

	// Main game loop
	while (!m_quit) {
		//Calculate the elapsed time since the beginning of the last frame
		currentTime = CL_System::get_time();
		timeElapsedMs = currentTime - lastTime;
		if (timeElapsedMs > 50)	{
			//Guard to ensure that the frame time isn't too long
			timeElapsedMs = 50;
		}
		lastTime = currentTime;

		m_frameCounter++;

		m_incomingMessages.clear();
		m_outgoingMessages.clear();

		while (true) {
			MessageData packet;
			u32 bytes_read = m_connection.ReceivePacket(packet.data, sizeof(packet.data));
			if (bytes_read == 0) {
				break;
			}
			m_incomingMessages.push_back(packet);
		}

		std::vector<MessageData>::iterator it = m_incomingMessages.begin();
		for (; it != m_incomingMessages.end(); ++it) {
			ProcessMessage((*it).data);
		}

		//Update the game state
		m_level->Update();
		m_updateSignal.invoke(timeElapsedMs);
		m_drawSignal.invoke();

		// Flip the display, showing on the screen what we drew since last call to flip()
		m_window.flip(0);
		
		ComposeUpdateMessage();

		if ((m_frameCounter % 6) == 0) {
			ComposeSyncMessage();
		}
		
		if (m_outgoingMessages.size() > 0) {
			std::vector<MessageData>::iterator it = m_outgoingMessages.begin();
			for (; it != m_outgoingMessages.end(); ++it)
			{
				m_connection.SendPacket((*it).data, (*it).size);
			}
		}		

		//Measure the time for this frame's update
		waitTime = 16 - (CL_System::get_time() - currentTime);
		if (waitTime < 0) {
			waitTime = 0;
		}

		// This call processes user input and other events
		CL_KeepAlive::process(0);

		// Sleep for a little while to avoid using too much of the CPU.
		CL_System::sleep(waitTime);
	}
}
コード例 #10
0
ファイル: DNS.cpp プロジェクト: nequeo/sockets
				NetworkInitializer()
				{
					InitializeNetwork();
				}
コード例 #11
0
GMI_RESULT MediaCenterService::Initialize( long_t Server_IP, uint16_t Server_UDP_Port, size_t SessionBufferSize )
{
    DEBUG_LOG( g_DefaultShareMemoryLogClient, e_DebugLogLevel_Info, "MediaCenterService::Initialize begin, passed Server_IP=%x, Server_UDP_Port=%d, SessionBufferSize=%d \n", ntohl(Server_IP), ntohs(Server_UDP_Port), SessionBufferSize );

    GMI_RESULT Result = InitializeNetwork( Server_IP, Server_UDP_Port, SessionBufferSize );
    if ( FAILED( Result ) )
    {
        DEBUG_LOG( g_DefaultShareMemoryLogClient, e_DebugLogLevel_Exception, "MediaCenterProxy::Initialize, InitializeNetwork failed, function return %x \n ", (uint32_t) Result );
        return Result;
    }

    m_MediaCenter = BaseMemoryManager::Instance().New<MediaCenter>();
    if ( NULL == m_MediaCenter.GetPtr() )
    {
        DeinitializeNetwork();
        DEBUG_LOG( g_DefaultShareMemoryLogClient, e_DebugLogLevel_Exception, "MediaCenterProxy::Initialize, MediaCenter object allocation failed, function return %x \n ", (uint32_t) GMI_OUT_OF_MEMORY );
        return GMI_OUT_OF_MEMORY;
    }

    ReferrencePtr<ApplicationPacket> Packet( BaseMemoryManager::Instance().New<ApplicationPacket>() );
    if ( NULL == Packet.GetPtr() )
    {
        m_MediaCenter = NULL;
        DeinitializeNetwork();
        DEBUG_LOG( g_DefaultShareMemoryLogClient, e_DebugLogLevel_Exception, "MediaCenterProxy::Initialize, ApplicationPacket object allocation failed, function return %x \n ", (uint32_t) GMI_OUT_OF_MEMORY );
        return GMI_OUT_OF_MEMORY;
    }

    Result = Packet->Initialize( (const uint8_t *)GMI_MEDIA_CENTER_MESSAGE_TAG, GMI_MEDIA_CENTER_MESSAGE_MAJOR_VERSION, GMI_MEDIA_CENTER_MESSAGE_MINOR_VERSION );
    if ( FAILED( Result ) )
    {
        Packet = NULL;
        m_MediaCenter = NULL;
        DeinitializeNetwork();
        DEBUG_LOG( g_DefaultShareMemoryLogClient, e_DebugLogLevel_Exception, "MediaCenterProxy::Initialize, ApplicationPacket object initialization failed, function return %x \n ", (uint32_t) Result );
        return Result;
    }

    m_CommandPipeline = BaseMemoryManager::Instance().New<ServerCommandPipelineManager>();
    if ( NULL == m_CommandPipeline.GetPtr() )
    {
        Packet->Deinitialize();
        Packet = NULL;
        m_MediaCenter = NULL;
        DeinitializeNetwork();
        DEBUG_LOG( g_DefaultShareMemoryLogClient, e_DebugLogLevel_Exception, "MediaCenterProxy::Initialize, ServerCommandPipelineManager object allocation failed, function return %x \n ", (uint32_t) GMI_OUT_OF_MEMORY );
        return GMI_OUT_OF_MEMORY;
    }

    Result = m_CommandPipeline->Initialize();
    if ( FAILED( Result ) )
    {
        m_CommandPipeline = NULL;
        Packet->Deinitialize();
        Packet = NULL;
        m_MediaCenter = NULL;
        DeinitializeNetwork();
        DEBUG_LOG( g_DefaultShareMemoryLogClient, e_DebugLogLevel_Exception, "MediaCenterProxy::Initialize, ServerCommandPipelineManager object initialization failed, function return %x \n ", (uint32_t) Result );
        return Result;
    }

    Result = m_CommandPipeline->RegisterPacket( Packet );
    if ( FAILED( Result ) )
    {
        m_CommandPipeline->Deinitialize();
        m_CommandPipeline = NULL;
        Packet->Deinitialize();
        Packet = NULL;
        m_MediaCenter = NULL;
        DeinitializeNetwork();
        DEBUG_LOG( g_DefaultShareMemoryLogClient, e_DebugLogLevel_Exception, "MediaCenterProxy::Initialize, ServerCommandPipelineManager object RegisterPacket failed, function return %x \n ", (uint32_t) Result );
        return Result;
    }

    DEBUG_LOG( g_DefaultShareMemoryLogClient, e_DebugLogLevel_Info, "MediaCenterService::Initialize end, passed Server_IP=%x, Server_UDP_Port=%d, SessionBufferSize=%d, function return =%x \n", ntohl(Server_IP), ntohs(Server_UDP_Port), SessionBufferSize, (uint32_t) Result );
    return Result;
}