Esempio n. 1
0
void QMplayer::sharing()
{
#ifdef QTOPIA
    if(!runClient())
    {
        runServer();
    }
#else
    if(!runServer())
    {
        runClient();
    }
#endif
}
Esempio n. 2
0
int main (int argc, char *argv[])
{
	Torture torture;
	const char bytes[] = "Hello, world!";

	torture.int8 = 0;
	torture.uint8 = 1;
	torture.int16 = 2;
	torture.uint16 = 3;
	torture.int32 = 4;
	torture.uint32 = 5;
	torture.int64 = 6;
	torture.uint64 = 7;
	//      torture.float32 = 3.14;
	//      torture.float64 = 3.1415;
	//      torture.bool = false;
	torture.int8Ptr = &torture.int8;
	torture.tuple = stringAllocateInitialize(bytes);

	if (argc != 2) {
		fprintf (stderr, "Usage: %s HOST\n", argv[0]);
		exit (EXIT_FAILURE);
	}

	runClient (argv[1], EtnToValue(&TortureType, &torture));

	exit (EXIT_SUCCESS);
}
Esempio n. 3
0
void
NetBench::run(NetBenchServer* server, NetBenchClient* client)
{
    std::cerr << "server "
              << "runServer: " << (m_runServer ? "yes " : "no ")
              << "runClient: " << (m_runClient ? "yes " : "no ")
              << "numConns: " << m_maxConns << " "
              << "numActive: " << m_maxActive << " "
              << "numBytes: " << m_numBytes << "\n";

#ifndef WINDOWS
    // the extra 20 fds are just some fluff in case we are called with
    // some small number of desired fds, like 1
    rlim_t rlfds = ((m_runServer && m_runClient ? 2 : 1) *
                    m_maxConns + 20);
    struct rlimit rl;
    rl.rlim_cur = rlfds * 2 + 20;
    rl.rlim_max = rlfds * 2 + 20;
    if (setrlimit(RLIMIT_NOFILE, &rl) < 0) {
        perror("setrlimit");
        exit(-1);
    }
#endif

    m_server = server;
    m_client = client;

    if (m_runServer) {
        server->run(m_host, 1, m_numBytes,
                    boost::bind(&NetBench::serverRunning, this));
    } else {
        runClient();
    }
}
Esempio n. 4
0
void
NetBench::serverRunning()
{
    if (m_runClient) {
        runClient();
    }
}
Esempio n. 5
0
int main(int argc, char** argv)
{
  int sockfd = -1;
  unsigned port = 0;

  if(argc != 3) {
    fprintf(stderr, "Usage: %s <server_addr> <server_port>\n", argv[0]);
    return 1;
  }

  port = atoi(argv[2]);

  sockfd = connectToServer(argv[1], port);

  if(sockfd == -1) {
    fprintf(stderr, "Could not connect to %s:%u\n", argv[1], port);
    return 1;
  }

  runClient(sockfd, argv[1], port);

  close(sockfd);

  return 0;
}
Esempio n. 6
0
int main(int argc, char ** argv) {
    QCoreApplication app(argc, argv);
#if defined(Q_OS_UNIX)
    catchUnixSignals({SIGQUIT, SIGINT, SIGTERM, SIGHUP});
#endif

    app.setApplicationName("helloworld");
    app.setApplicationVersion("1.0.0");

    QCommandLineParser parser;
    parser.setApplicationDescription("a HelloWorld example for http client and server.");
    parser.addHelpOption();
    parser.addVersionOption();
    parser.addPositionalArgument("mode",
            "working mode: server, client or weather. default: server");

//    parser.addOption({
//            {"l", "listen"},
//            "listening tcp port number in server mode (default 8080)",
//            "portNo", "8080"});
//    parser.addOption({
//            {"u", "url"},
//            "fetch url data in client mode",
//            "address", "http://www.google.com"});
//    parser.addOption({
//            {"g", "geolocation"},
//            "a city name [,country name] in weather mode, default: Tehran",
//            "city", "Tehran"});
    parser.process(app);


    QStringList posArgs = parser.positionalArguments();
    if ( posArgs.size() != 1 ) {
        parser.showHelp(0);

    } else {
        const auto& mode = posArgs.at(0);

        if ( mode == QLatin1Literal("server") )
            runServer(parser.value("listen"));

#if defined(QHTTP_HAS_CLIENT)
        else if ( mode == QLatin1Literal("client") )
            runClient(parser.value("url"));

        else if ( mode == QLatin1Literal("weather") )
            runWeatherClient(parser.value("geolocation"));
#else
        else if ( mode == QLatin1Literal("client")
                || mode == QLatin1Literal("weather") )
            qDebug("qhttp::client has not been enabled at build time");
#endif // QHTTP_HAS_CLIENT
    }

    return 0;
}
Esempio n. 7
0
int main(int argc, char** argv) {
  key_t key = ftok("chat", 3141596);

  if(argc != 2) {
    fprintf(stderr, "Invalid arguments.");
  } else if(strcmp(argv[1], "-s") == 0) {
    runServer(key);
  } else if(strcmp(argv[1], "-c") == 0) {
    runClient(key);
  }

  return 0;
}
Esempio n. 8
0
int main(int argc, char* argv[])
{
    std::string profile;
    for (int i = 1; i < argc; ++i) {
        std::string arg(argv[i]);
        if (arg == "server") {
            profile = "server";
        }
    }

    if (profile == "server") {
        return runServer(argc, argv);
    }
    return runClient(argc, argv);
}
Esempio n. 9
0
int main(const int argc, const char* argv[]) {
    if (argc == 2) {
        if (argv[1] == std::string("client")) {
            runClient();
            return 0;
        } else if (argv[1] == std::string("server")) {
            runServer();
            return 0;
        }
    }

    printHelp();

    return 1;
}
Esempio n. 10
0
int main(int argc, char ** argv) {
	key_t key = ftok("kozel", 0);
	int msgId = msgget(key, IPC_CREAT | 0666);
	printf("key=%d\n", key);
	printf("msgId=%d\n", msgId);	
	
	switch(getKey(argc, argv)) {
		case server:	runServer(msgId);
				break;
		case client:	runClient(msgId);
				break;
		default:	printf("Error\n");
				break;
	}	

	return 0;
}
Esempio n. 11
0
int main(int argc, char ** argv)
{
	try
	{
		runClient();
	}
	catch(const Fall::Exception & exception)
	{
		std::cerr << "Unhandled application exception: " << exception.getMessage() << std::endl;
		return 1;
	}
	catch(const std::exception & exception)
	{
		std::cerr << "Unhandled standard exception: " << exception.what() << std::endl;
		return 2;
	}
	catch(...)
	{
		std::cerr << "Unhandled exception of unknown type" << std::endl;
		return 3;
	}
	return 0;
}
Esempio n. 12
0
void QMplayer::okClicked()
{
    if(screen == QMplayer::ScreenInit || screen == QMplayer::ScreenEncoding)
    {
        QString dir = "";
        bool hit = false;
        QStringList list;
        QStringList downList;
        QStringList nameList;
        QMessageBox::StandardButton answer = QMessageBox::NoButton;
        QMessageBox::StandardButton moreAnswer = QMessageBox::NoButton;

        list << mpargs;
        list << mplist;

        if (mpgui)
        {
            QListWidgetItem *sel = lw->currentItem();
            if(sel == NULL)
            {
                return;
            }
            if(sel == scanItem)
            {
                scan();
                return;
            }
            if(sel == sharingItem)
            {
                sharing();
                return;
            }
            if(sel == encodingItem)
            {
                if(screen != ScreenEncoding)
                {
                    showScreen(ScreenEncoding);
                    if(lw->count() > NUM_MENU_ITEMS)
                    {
                        QListWidgetItem *item = lw->item(NUM_MENU_ITEMS);
                        item->setSelected(true);
                    }
                }
                else
                {
                    showScreen(ScreenInit);
                }
                return;
            }

            for(int i = NUM_MENU_ITEMS; i < lw->count(); i++)
            {
                QListWidgetItem *item = lw->item(i);
                QString path = item->text();
                bool isDir = isDirectory(path);
                if(isDir)
                {
                    if(hit)
                    {
                        break;
                    }
                    dir = path;
                }
                hit |= (item == sel);
                if(!hit || isDir)
                {
                    continue;
                }
                if(!dir.startsWith("http://"))
                {
                    list.append(dir + "/" + path);      // add local files to playlist
                    continue;
                }
                if(moreAnswer == QMessageBox::NoButton)
                {
                    answer = QMessageBox::question(this, "qmplayer", path, QMessageBox::Save | QMessageBox::Open | QMessageBox::Cancel);
                }
                if(answer == QMessageBox::Cancel)
                {
                    break;
                }
                if(answer == QMessageBox::Open)
                {
                    list.append(dir + pathToUrl(path));      // append to playlist if we just play (no download)
                }
                downList.append(dir + pathToUrl(path));
                nameList.append(path);
                if(moreAnswer != QMessageBox::YesToAll)
                {
                    moreAnswer = QMessageBox::question(this, "qmplayer", tr("Next file?"),
                                                       QMessageBox::Yes | QMessageBox::No | QMessageBox::YesToAll);

                    if(moreAnswer == QMessageBox::No)
                    {
                        break;
                    }
                }
            }
            for(int i = 0; i < downList.count(); i++)
            {
                QString url = downList[i];
                int slashIndex = url.lastIndexOf('/');
                if(slashIndex < 0)
                {
                    continue;
                }
                QString filename = nameList[i];
                QString destPath = QDir::homePath() + "/" + filename;
                if(QDir("/media/card").exists())
                {
                    destPath = "/media/card/" + filename;
                }
                bool justCheck = list.contains(url);
                if(!download(url, destPath, filename, justCheck))
                {
                    return;
                }
                if(justCheck)
                {
                    continue;
                }
                // Add downloaded file to list
                list.append(destPath);
            }
        }

        if(list.count() > mpargs.count())
        {
            if(screen == ScreenEncoding)
            {
                encode(list.at(0));
            }
            else
            {
                if (isPlaylist(list[mpargs.count()]))
                    list.insert(mpargs.count(),"-playlist");
                play(list);
            }
        }
    }
    else if(screen == QMplayer::ScreenPlay)
    {
        if(processRunning(process))
        {
            process->write(" ");
        }
        showScreen(QMplayer::ScreenStopped);
    }
    else if(screen == QMplayer::ScreenStopped)
    {
        if(processRunning(process))
        {
            process->write(" ");
#ifdef QTOPIA
            // Workaround unpause not working for alsa out in mplayer glamo.
            // We send left key to make mplayer start playing.
            process->write("\x1b""[D");
#endif
        }
        showScreen(QMplayer::ScreenPlay);
    }
    else if(screen == QMplayer::ScreenConnect)
    {
        runClient();
    }
    else if(screen == QMplayer::ScreenTube)
    {
        this->screen = QMplayer::ScreenInit;
        okClicked();
    }
}
Esempio n. 13
0
int main(int, char**)
{
     return runClient();
}