Exemple #1
0
static void startTcpServers(void)
{
    tcpServer(port, SERVER_JSON);
    logInfo("TCP JSON server listening on port %d\n", port);
    tcpServer(port + 1, SERVER_JSON_STREAM);
    logInfo("TCP JSON stream server listening on port %d\n", port + 1);
    tcpServer(port + 2, SERVER_NMEA0183_STREAM);
    logInfo("TCP NMEA0183 server listening on port %d\n", port + 2);
}
/***********************************************************************
 * Spawn TCP proxy server given server URI
 **********************************************************************/
void PothosUtilBase::proxyServer(const std::string &, const std::string &uriStr)
{
    //set stdio to be unbuffered to prevent IO backup when this is a subprocess
    std::cout.setf(std::ios::unitbuf);
    std::cerr.setf(std::ios::unitbuf);
    std::clog.setf(std::ios::unitbuf);

    Pothos::ScopedInit init;

    //parse the URI
    const std::string defaultUri = "tcp://"+Pothos::Util::getWildcardAddr(Pothos::RemoteServer::getLocatorPort());
    Poco::URI uri(uriStr.empty()?defaultUri:uriStr);
    const std::string &host = uri.getHost();
    const std::string &port = std::to_string(uri.getPort());
    if (uri.getScheme() != "tcp")
    {
        throw Pothos::Exception("PothosUtil::proxyServer("+uriStr+")", "unsupported URI scheme");
    }

    //create server socket
    Poco::Net::SocketAddress sa(host, port);
    Poco::Net::ServerSocket serverSocket(sa);
    Poco::Net::TCPServerConnectionFactory::Ptr factory;
    factory = new MyTCPServerConnectionFactory(this->config().hasOption("requireActive"));
    Poco::Net::TCPServer tcpServer(factory, serverSocket);

    //start the server
    tcpServer.start();
    std::cout << "Host: " << serverSocket.address().host().toString() << std::endl;
    std::cout << "Port: " << serverSocket.address().port() << std::endl;

    //wait here until the term signal is received
    this->waitForTerminationRequest();
}
/*!
 * Creates a QxtHttpsServerConnector with the given \a parent.
 */
QxtHttpsServerConnector::QxtHttpsServerConnector(QObject* parent) 
: QxtHttpServerConnector(parent, new QxtSslServer)
{
    // initializers only
    // Reparent the SSL server
    tcpServer()->setParent(this);
}
Exemple #4
0
int
ettConstructor()
{
  localobject->privated = (void *) &ETP;
  bzero ((char *) &ETP,sizeof(ETP));

  objClass object = localobject;
  ET_priv *etp = (ET_priv *) object->privated;

  int id, res;
  pthread_attr_t attr;

  printf("ettConstructor reached\n");

  etp->id = 0;
  etp->exit = 0;

  tcpState = DA_BOOTED;
  if(codaUpdateStatus("booted") != ET_OK) return(ET_ERROR);

  printf("ettConstructor: calling tcpServer(%s, %s)\n",localobject->name, mysql_host);
  tcpServer(localobject->name, mysql_host); /*start server to process non-coda commands sent by tcpClient*/

  return(ET_OK);
}
int main()
{
	EventLoop baseLoop;
	InetAddress listenAddr("127.0.0.1", 8888);
	std::unique_ptr<TcpServer> tcpServer(new TcpServer(&baseLoop, listenAddr, "test"));
	tcpServer->setMessageCallback(std::move(onMessage));
	tcpServer->start();

	baseLoop.loop();

	return 0;
}
Exemple #6
0
int _tmain(int argc, _TCHAR* argv[])
{
	WSADATA wsaData;
	WSAStartup(MAKEWORD(2, 2), &wsaData);
	{
		CLibevServer tcpServer(9995);
		tcpServer.runServer();
	}

	system("pause");
	WSACleanup();
	return 0;
}
Exemple #7
0
int main(int argc, char *argv[]) {
	if (argc != 4) {
		printf("It should contain four arguments, including TCP/UDP, buffer_size and num_of_threads\n");
		return 1;
	}

	int bufferSize   = atoi(argv[2]);
	int numOfThreads = atoi(argv[3]);
	if (strcmp(argv[1], "TCP") == 0)
		tcpServer(bufferSize, numOfThreads);
	else
		udpServer(bufferSize, numOfThreads);
	return 0;
}
Exemple #8
0
void NetworkServer::operator()()
{
    // Asio service
    try
    {
        TcpServer tcpServer( m_io, m_msgHandler, m_tcpServerPort );
        UdpServer udpServer( m_io, m_msgHandler, m_udpServerPort );
        m_io.run();
    }
    catch(std::exception &e)
    {
        std::cerr << e.what() << std::endl;
    }
}
void PothosUtilBase::proxyServer(const std::string &, const std::string &uriStr)
{
    Pothos::init();

    //parse the URI
    const std::string defaultUri = "tcp://0.0.0.0:"+Pothos::RemoteServer::getLocatorPort();
    Poco::URI uri(uriStr.empty()?defaultUri:uriStr);
    const std::string &host = uri.getHost();
    const std::string &port = std::to_string(uri.getPort());
    if (uri.getScheme() != "tcp")
    {
        throw Pothos::Exception("PothosUtil::proxyServer("+uriStr+")", "unsupported URI scheme");
    }

    //create server socket
    Poco::Net::SocketAddress sa(host, port);
    Poco::Net::ServerSocket serverSocket(sa);
    Poco::Net::TCPServerConnectionFactory::Ptr factory(new MyTCPServerConnectionFactory());
    Poco::Net::TCPServer tcpServer(factory, serverSocket);

    //start the server
    std::cout << "Host: " << serverSocket.address().host().toString() << std::endl;
    std::cout << "Port: " << serverSocket.address().port() << std::endl;
    serverSocket.listen();
    tcpServer.start();

    //monitor active connections in monitor mode
    if (this->config().hasOption("requireActive"))
    {
        //create a TCP connection monitor thread
        MyTCPConnectionMonitor monitor(tcpServer);
        Poco::Thread monitorThread;
        monitorThread.start(monitor);

        //wait here until the term signal is received
        this->waitForTerminationRequest();

        //end the monitor thread
        monitor.running = false;
        monitorThread.join();
    }
    else
    {
        //wait here until the term signal is received
        this->waitForTerminationRequest();
    }
}
Exemple #10
0
void startServer()
{
    //屏蔽PIPE信号
    struct sigaction action;
    action.sa_handler = SIG_IGN;
    sigemptyset(&action.sa_mask);
    action.sa_flags = 0;
    if (sigaction(SIGPIPE, &action, NULL) < 0)
    {
        LOG_ERROR("sigaction failure");
        return;
    }

    const INT1* pMaxFiles = CServer::getInstance()->getConf()->getConfig("controller", "max_open_files");
    INT4 maxFiles = (NULL == pMaxFiles) ? 20000 : atol(pMaxFiles);
    //设置进程允许打开最大文件数
    struct rlimit rt;
    rt.rlim_max = rt.rlim_cur = maxFiles;
    if (setrlimit(RLIMIT_NOFILE, &rt) < 0) 
    {
        LOG_ERROR("setrlimit error");
        return;
    }

    //初始化消息树
    if (!CServer::getInstance()->getMsgTreeNodeMgr()->init())
    {
        LOG_ERROR("msg tree node mgr init failure");
        return;
    }

    //初始化handler
    if (!CServer::getInstance()->getHandlerMgr()->init())
    {
        LOG_ERROR("handler mgr init failure");
        return;
    }
    CServer::getInstance()->getHandlerMgr()->start();

    //读取of服务端口
    const INT1* pOfport = CServer::getInstance()->getConf()->getConfig("controller", "openflow_server_port");
    UINT4 ofPort = (NULL == pOfport) ? 6633 : atoll(pOfport);

    //读取接收线程个数
    const INT1* pRecvThreadNum = CServer::getInstance()->getConf()->getConfig("controller", "recv_thread_num");
    UINT4 recvThreadNum = (pRecvThreadNum == NULL) ? 10 : atol(pRecvThreadNum);

    //启动of server
    CSmartPtr<CRecvWorker> ptrOfRecvWorker(new COfpRecvWorker());
    CTCPServer tcpServer(0, ofPort, recvThreadNum, maxFiles, ptrOfRecvWorker);
    if (!tcpServer.init())
    {
        LOG_ERROR("ofp server init failure");
        return;  
    }

    //读取http服务端口
    const INT1* pHttpport = CServer::getInstance()->getConf()->getConfig("restful", "http_server_port");
    UINT4 httpPort = (NULL == pHttpport) ? 8081 : atoll(pHttpport);

    //启动http server
    CSmartPtr<CRecvWorker> ptrHttpRecvWorker(new CHttpRecvWorker());
    CTCPServer httpServer(0, httpPort, recvThreadNum, maxFiles, ptrHttpRecvWorker);
    if (!httpServer.init())
    {
        LOG_ERROR("http server init failure");
        return;  
    }

    LOG_INFO("dcfabric server start success");
    while (true)
    {
        sleep(30);
        CServer::getInstance()->getTopoMgr()->printPaths();
    }
}
void startTcpServer(ServerCommunicator *com) {
	TcpServer tcpServer(*com);
	bool shouldContine = true;
	while (shouldContine)
		shouldContine = tcpServer.update();
}