当前位置: 首页>>代码示例>>C++>>正文


C++ SocketServer类代码示例

本文整理汇总了C++中SocketServer的典型用法代码示例。如果您正苦于以下问题:C++ SocketServer类的具体用法?C++ SocketServer怎么用?C++ SocketServer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SocketServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Socket

/*
 * This method has two functionalities
 * -It waits for incoming connections if local port is defined
 * -It tries to connect to remote host if local host is not defined
 */
void IPCommMonitorThread::Connect(Socket*& s)
{
	// This trickery here is because if there are no sockets (Socket::nofSockets_)
	// WSACleanup gets called and then SOAP gets messed up.
	// And creating a new socket for a new connection seems to work better
	// than using the old when re-connecting / re-listening.
	Socket* new_s = new Socket();
	delete s;
	s = new_s;

	// If local port is defined start open listening socket
	SocketServer ss;
	if( m_LocalPort )
	{
		Util::Info("[IPComm] Listen for incoming connection...");
		String remoteHost( "[IPComm] Connected! Remote host : " );
		ss.Accept( s, m_LocalPort, 1, remoteHost );
		Util::Info(remoteHost);
	}
	// If not start connecting
	else
	{
		Util::Info("[IPComm] Connecting...");
		ss.Connect( s, m_RemoteHost.c_str(), m_RemotePort );
		Util::Info("[IPComm] Connected!");
	}
}
开发者ID:cdaffara,项目名称:symbiandump-os2,代码行数:32,代码来源:IPComm.cpp

示例2: sReadLoop

void* SocketServer::sReadLoop(void* data){
	
	SocketServer* pthis = (SocketServer*)data;
	pthis->ReadLoop();
	
	return NULL;
}
开发者ID:baz,项目名称:upnpx,代码行数:7,代码来源:socketserver.cpp

示例3: main

int main ()
{
    Log l("server ");

    Registry::add("Test", new TestImpl());

    // server
    EventDriver ed;
    SocketServer srv;
    srv.start(8091, &ed);
    ed.run();
    return 0;
}
开发者ID:ciecet,项目名称:rop,代码行数:13,代码来源:server.cpp

示例4: main

/*
 * Main Entry function
 */
int main(int argc, char** argv) {
	Order::init();

	Currency *usd = new Currency("usd");
	Currency *btc = new Currency("btc");
	Currency *ltc = new Currency("ltc");

	new Market(BTC_USD, usd, btc);
	new Market(LTC_USD, ltc, usd);
	new Market(BTC_LTC, btc, ltc);

	SocketServer *server = new SocketServer("/tmp/BitcoinTradeEngine.sock");
	server->start();
	Order::unInit();
	return 0;
}
开发者ID:allada,项目名称:BitcoinTradeEngine,代码行数:19,代码来源:main.cpp

示例5: TransporterService

bool
TransporterRegistry::start_service(SocketServer& socket_server)
{
  DBUG_ENTER("TransporterRegistry::start_service");
  if (m_transporter_interface.size() > 0 && !nodeIdSpecified)
  {
    g_eventLogger.error("TransporterRegistry::startReceiving: localNodeId not specified");
    DBUG_RETURN(false);
  }

  for (unsigned i= 0; i < m_transporter_interface.size(); i++)
  {
    Transporter_interface &t= m_transporter_interface[i];

    unsigned short port= (unsigned short)t.m_s_service_port;
    if(t.m_s_service_port<0)
      port= -t.m_s_service_port; // is a dynamic port
    TransporterService *transporter_service =
      new TransporterService(new SocketAuthSimple("ndbd", "ndbd passwd"));
    if(!socket_server.setup(transporter_service,
			    &port, t.m_interface))
    {
      DBUG_PRINT("info", ("Trying new port"));
      port= 0;
      if(t.m_s_service_port>0
	 || !socket_server.setup(transporter_service,
				 &port, t.m_interface))
      {
	/*
	 * If it wasn't a dynamically allocated port, or
	 * our attempts at getting a new dynamic port failed
	 */
	g_eventLogger.error("Unable to setup transporter service port: %s:%d!\n"
		 "Please check if the port is already used,\n"
		 "(perhaps the node is already running)",
		 t.m_interface ? t.m_interface : "*", t.m_s_service_port);
	delete transporter_service;
	DBUG_RETURN(false);
      }
    }
    t.m_s_service_port= (t.m_s_service_port<=0)?-port:port; // -`ve if dynamic
    DBUG_PRINT("info", ("t.m_s_service_port = %d",t.m_s_service_port));
    transporter_service->setTransporterRegistry(this);
  }
  DBUG_RETURN(true);
}
开发者ID:A-eolus,项目名称:mysql,代码行数:46,代码来源:TransporterRegistry.cpp

示例6: handle

int PsCacheSetHandler::handle(PcMsg * msg , SocketServer & server , int peer)
{
  PcMsgSetReq * set = (PcMsgSetReq *)msg;
  PcMsgSetRes res;

  COMMON_LOGGER_DEBUG("set command , %s %s\n" , set->getKey().c_str() , set->getValue().c_str());

  int len = 0;

#ifndef __STORAGE_FASTDB__
  PsData * data = PsDataMgr::instance()->set(const_cast<char *>(set->getKey().c_str()) , 
  	const_cast<char *>(set->getValue().c_str()) , strlen(set->getValue().c_str()));
  if (data)
  {
    res.setCode(0); 
    res.setDesc("success");  
    res.setValue(data->value);
    len += strlen(data->value);
	len += 4;
  }
  else
  {
    res.setCode(1);
    res.setDesc("failed");
  }
#else
  bool ret = PsDataMgr::instance()->set(const_cast<char *>(set->getKey().c_str()) , 
  	const_cast<char *>(set->getValue().c_str()) , strlen(set->getValue().c_str()) , -1);
  if (ret)
  {
    res.setCode(0); 
    res.setDesc("success");  
    res.setValue(set->getValue());
    len += strlen(set->getValue().c_str());
	len += 4;
  }
  else
  {
    res.setCode(1);
    res.setDesc("failed");
  }  
#endif
  
  res.setType(PSCACHE_MSG_SET_RES);
  res.setLength(80 + len);  
  res.setVersion(msg->getVersion());
  
  PscacheMsgResParser parser;
  char * buffer = new char[80 + len];
  (void)memset(buffer , 0x00 , 80 + len);
  parser.compile(res , buffer);
    
  server.write(peer , buffer , 80 + len);

  delete [] buffer;
  
  return 0;
}
开发者ID:gilbertwang1981,项目名称:cache,代码行数:58,代码来源:pchandler.cpp

示例7: serverCallback

static void* serverCallback(void* arg)
{
  try
    {
      ServerData* data = static_cast<ServerData*>(arg);
      SocketServer* server = new SocketServer;
      std::string host = "127.0.0.1";
      if (!data->isServer)
	  host = "127.0.0.2";

      server->run(serverHandleCallback, host);
      delete server;
      data->serverThread->exit();
    }
  catch (ISocket::Exception& e)
    {
      std::cerr << e.what() << std::endl; 
    }

  return NULL;
}
开发者ID:Bootz,项目名称:VoIP_Project_archive,代码行数:21,代码来源:main.cpp

示例8: main

int main(void)
{
    try
    {
        std::vector<DylThread*> vectorOfThreads;
        SocketServer servSock = SocketServer (2000);
        while (1) 
        {
            std::cout << "I am a server!" << std::endl;

            //create a new socket
            
            Socket s = servSock.Accept(); // blocking call - waits for request

            //put that new socket into a thread
            DylThread *dThr =  new DylThread(s, true);
            vectorOfThreads.push_back(dThr);

            std::cout << "hm +" << vectorOfThreads << std::endl;

          for (DylThread* i: vectorOfThreads)
              {
                std::cout << "hm " << i << std::endl;
              }

        }




    }


    // catch(...)
    catch(std::string e)
    {
        std::cout << e << " Caught unexpected exception" << std::endl;
    }
}
开发者ID:dharness,项目名称:se3336_lab3,代码行数:39,代码来源:Server.cpp

示例9: socketServer

void Monitor::CreateSocketServer(MonitorConfiguration *config)
{
	static SocketServer socketServer(config,0) ;

	static SocketServer fms32ProServer(config,1000) ;
	fms32ProServer.m_ServerModus = SocketThread::fms32pro ;

	static SocketServer crusaderServer(config,2000) ;
	crusaderServer.m_ServerModus = SocketThread::crusader ;

	socketServer.Start() ;
	fms32ProServer.Start() ;
	crusaderServer.Start() ;
}
开发者ID:phl0,项目名称:monitord,代码行数:14,代码来源:Monitor.cpp

示例10: InitSndCard

void Monitor::MainLoop()
{
	// Soundkarte initialisieren
	InitSndCard() ;

	/********************************************************/


	static SocketServer socketServer(&m_MonitorConfig,m_MonitorConfig.m_socketFilterFileName ,0) ;
	socketServer.Start() ;
	FILE_LOG(logINFO) << "monitord socketserver started" ;


	static SocketServer fms32ProServer(&m_MonitorConfig,m_MonitorConfig.m_socketFilterFileName ,1000) ;
	fms32ProServer.m_ServerModus=SocketThread::fms32pro ;
	fms32ProServer.Start() ;
	FILE_LOG(logINFO) << "fms32pro socketserver started" ;

	static SocketServer crusaderServer(&m_MonitorConfig,m_MonitorConfig.m_socketFilterFileName ,2000) ;
	crusaderServer.m_ServerModus=SocketThread::crusader ;
	crusaderServer.Start() ;
	FILE_LOG(logINFO) << "crusader socketserver started" ;


	/*******************************************************/

	#ifdef PLUGINS
	//GetPluginsManager().loadPlugin("plugins/.libs/libmplugin_mysql-0.dll",NULL);
	GetPluginsManager().loadScriptFilter(m_MonitorConfig.m_pluginFilterFileName) ;
	GetPluginsManager().loadPluginsFromConfigNode(&m_MonitorConfig.m_configDataPlugins);
	FILE_LOG(logDEBUG) << "PluginManager started" ;
	#endif
	/*********************************************************/

	while (!m_bWantStop)
	{
		/**
		 * Wer sich fragt, wo eigentlich denn die Arbeit gemacht wird:
		 * Die drei SocketServer sind eigenstaendige Threads. Die bedienen
		 * die TCP/IP Verbindungen und laufen unabhaegig.
		 *
		 * Die eigentliche (Ton) Auswertung erfolgt in jeweils einem Thread
		 * pro Soundkarte. Diese Threads werden im InitSndCard gestartet.
		 *
		 * Dann gibt es noch den GlobalDispatcher. Er ist auch ein eigenstaendiger
		 * Thread. Er wird von dem Auswerten mit ResultSets versorgt. Die Auswerter
		 * haben damit Ihren Teil erledigt.
		 * Der Dispatcher verteilt dann die Results an alle Sockets und Plugins (ohne die
		 * Auswerter zu blockieren)
		 *
		 */

		usleep(100);
		// Wie man sieht: hier gibt es im Moment nichts zu tun :-
	}

	FILE_LOG(logINFO) << PACKAGE_NAME << " shutting down..."  ;
	StopSndCard() ;

	FILE_LOG(logINFO) << "stopping socketserver monitord";
	socketServer.m_bWantStop=true ;
	FILE_LOG(logINFO) << "stopping socketserver FMS32";
	fms32ProServer.m_bWantStop=true ;
	FILE_LOG(logINFO) << "stopping socketserver Crusader";
	crusaderServer.m_bWantStop=true ;

	usleep(1000) ;
	m_SignalStopped->SetSignal() ;
	usleep(500) ;
	FILE_LOG(logINFO) << "all done. " << PACKAGE_NAME << " exiting";
}
开发者ID:phl0,项目名称:monitord,代码行数:71,代码来源:Monitor.cpp

示例11: acceptHandler

void* SocketServer::acceptHandler(void* param)
{
	SocketServer* instance = (SocketServer*)param;

	instance->doAcceptLoop();
}
开发者ID:dantia,项目名称:liferay-nativity,代码行数:6,代码来源:socket.cpp

示例12: readHandler

void* SocketServer::readHandler(void* param)
{
	SocketServer* instance = (SocketServer*)param;

	instance->doReadLoop();
}
开发者ID:dantia,项目名称:liferay-nativity,代码行数:6,代码来源:socket.cpp

示例13: socketServerThread_C

void* 
socketServerThread_C(void* _ss){
  SocketServer * ss = (SocketServer *)_ss;
  ss->doRun();
  return 0;
}
开发者ID:ForcerKing,项目名称:ShaoqunXu-mysql5.7,代码行数:6,代码来源:SocketServer.cpp

示例14: main

int main(int argc, char *argv[]) 
{
	SocketServer* socketServer = new SocketServer();
	socketServer->Start(MAX_CLIENT_COUNT);
	while (getch()!=27)	{}
}
开发者ID:DimaLupyak,项目名称:SocketChatCgg,代码行数:6,代码来源:socketServerMain.cpp

示例15: clientThread

void clientThread(int clientsock)
{
    while (1) {
        if(g_server.getClient(clientsock).wantClose)
            break;
        std::string raw_buff;
        
        char buff[1024] = {0};
        if(recv(clientsock, buff, sizeof(buff), 0)<=0){
            break;
        }
        raw_buff += buff;
        
        do{
            size_t endpos = raw_buff.find("$");
            if (endpos==-1)
                break;
            const std::string msg = raw_buff.substr(0, endpos);
            raw_buff = raw_buff.substr(endpos+1);
            
            g_server.mtx.lock();
            g_server.ondata(clientsock, msg);
            g_server.mtx.unlock();
        }while(1);
    }
    g_server.rmClient(clientsock);
}
开发者ID:gittor,项目名称:TankWorld,代码行数:27,代码来源:SocketServer.cpp


注:本文中的SocketServer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。