Ejemplo n.º 1
0
/* ==============================================
	main task routine
   ============================================== */
int main(void) {
	pool_memadd((uint32_t)pool, sizeof(pool));

#ifdef DEBUG
	dbg.start();
#endif
	char	ch;
	CSocket *client;
	CSocket server;

	server.create(SOCK_STREAM);
	server.bind(23);	// bind to port 23
	server.listen();	// enter listen mode

	// Enter an endless loop
	while(1){
		client = server.accept();						// accept and create a connected socket
		if ( client!=NULL ) {
			dbg.println("Client connected\n");
			while( client->isConnected() ) {			// check connection
				if ( client->read(&ch, sizeof(ch)) ) {	// read from client
					client->write(&ch, sizeof(ch));		// echo to client
				}
			}
			dbg.println("Client disconnected\n");
			delete client;								// free client after disconnected
		}
	}
	return 0 ;
}
Ejemplo n.º 2
0
void CDebug::run() {
	if ( m_port==DBG_USB ) {
		//
		// USB port
		//
		CSerial cdc(USB);
		m_shell.assign(cdc);
		while(1) {
			if ( cdc.isConnected() ) {
				m_shell.run();
			}
		}

	} else {
		//
		// Telnet (TCP/IP port 23)
		//
		CSocket server;
		CSocket *client;

		server.create(SOCK_STREAM);
		server.bind(TELNET_PORT);
		server.listen();
		while (1) {
			if ((client = server.accept()) != NULL) {
				client->keepAlive(3, 3, 3);	// set keep alive in 3 seconds for idle, try in 3 seconds and 3 times
				m_shell.assign(client);
				m_shell.run();
				delete client;
			}
		}
	}
}
Ejemplo n.º 3
0
void acceptSock(CSocket& pSocket, int pType)
{
	CSocket* newSock = pSocket.accept();
	if (newSock == 0)
		return;

	// Server ip bans.
	if (pType == SOCK_SERVER)
	{
		CString ip(newSock->getRemoteIp());
		for (std::vector<CString>::const_iterator i = ipBans.begin(); i != ipBans.end(); ++i)
		{
			if (ip.match(*i))
			{
				printf("Rejected server: %s matched ip ban %s\n", ip.text(), i->text());
				newSock->disconnect();
				delete newSock;
				return;
			}
		}
	}

	//newSock->setOptions( SOCKET_OPTION_NONBLOCKING );
	serverlog.out(CString() << "New Connection: " << CString(newSock->getRemoteIp()) << " -> " << ((pType == SOCK_PLAYER) ? "Player" : "Server") << "\n");
	if (pType == SOCK_PLAYER || pType == SOCK_PLAYEROLD)
		playerList.push_back(new TPlayer(newSock, (pType == SOCK_PLAYEROLD ? true : false)));
	else serverList.push_back(new TServer(newSock));
}
Ejemplo n.º 4
0
void acceptNewPlayers(CSocket& pSocket)
{
	CSocket* newSock = pSocket.accept();
	if(newSock == 0)
		return;

	newPlayers.add(new CPlayer(newSock));
	printf( "[%s] Incoming connection: [%s]\n", getTimeStr(1).text(), newSock->tcpIp() );
}
Ejemplo n.º 5
0
void	CPecaCore::threadServer()
{
	CPecaServer	server;

	CSocket	sockServer;
	sockServer.bind();

	while (1) {
		CSocket*	psock = sockServer.accept();
		if (psock) {
			char strIP[64];
			psock->GetFromHost().toStr(strIP);
			LOG_DEBUG(_T("%s から接続要求"), strIP);

			boost::thread(boost::bind(&CPecaCore::handshake, this, psock));
		}
		::Sleep(10);
	}


	//server.

}