Ejemplo n.º 1
0
QXmppSocksServer::QXmppSocksServer(QObject *parent)
    : QObject(parent)
{
    m_server = new QTcpServer(this);
    connect(m_server, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));

    m_server_v6 = new QTcpServer(this);
    connect(m_server_v6, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
}
Ejemplo n.º 2
0
Server::Server(const int port, const int size, QWidget *parent) :
    QWidget(parent),
    size(size),
    menu(new QVBoxLayout(this)),
    field(new Widget(size, "green", "blue")),
    myServer(new QTcpServer(this)),
    txtInfo(new QTextEdit),
    nextBlockSize(0)
{
    connect(field, SIGNAL(sendNumber(int)), this, SLOT(sendToClient(int)));
    if (!myServer->listen(QHostAddress::Any, port))
    {
        QMessageBox::critical(0, "Server Error",
                              "Unable to start the server:"
                              + myServer->errorString()
                             );
        myServer->close();
        return;
    }

    connect(myServer, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));

    txtInfo->setReadOnly(true);

    menu->addWidget(new QLabel("<H1>Server</H1>"));
    menu->addWidget(txtInfo);
    menu->addLayout(field->menu);
    setLayout(menu);
}
Ejemplo n.º 3
0
// ----------------------------------------------------------------------
MyServer::MyServer(int nPort, QWidget* pwgt ) : QWidget(pwgt)
                                                    , m_nNextBlockSize(0)
{  //создается tcp сервер и ставится на прослушку заданного порта
    m_ptcpServer = new QTcpServer(this);

    if (!m_ptcpServer->listen(QHostAddress::Any, nPort)) {
        QMessageBox::critical(0,
                              "Server Error",
                              "Unable to start the server:"
                              + m_ptcpServer->errorString()
                             );
        m_ptcpServer->close();
        return;
    }

    connect(m_ptcpServer , SIGNAL(newConnection()) , this , SLOT(slotNewConnection()));
// создается бокс, в который будут выводиться все серверные сообщения
    m_ptxt = new QTextEdit;

    m_ptxt->setReadOnly(true);

    QVBoxLayout* pvbxLayout = new QVBoxLayout;

    pvbxLayout->addWidget(new QLabel("<H1>Сумматор</H1>"));

    pvbxLayout->addWidget(m_ptxt);

    setLayout(pvbxLayout);

    i = 0;//индикатор кол-ва подключенных клиентов. Макс. - 4!
}
Ejemplo n.º 4
0
SocketApi::SocketApi(QObject* parent)
    : QObject(parent)
    , _excludes(0)
{
    QString socketPath;

    if (Utility::isWindows()) {
        socketPath = QLatin1String("\\\\.\\pipe\\")
        + QLatin1String("ownCloud");
        // TODO: once the windows extension supports multiple
        // client connections, switch back to the theme name
        // See issue #2388
        // + Theme::instance()->appName();
    } else if (Utility::isMac()) {
        // This must match the code signing Team setting of the extension
        // Example for developer builds (with ad-hoc signing identity): "" "com.owncloud.desktopclient" ".socketApi"
        // Example for official signed packages: "9B5WD74GWJ." "com.owncloud.desktopclient" ".socketApi"
        socketPath = SOCKETAPI_TEAM_IDENTIFIER_PREFIX APPLICATION_REV_DOMAIN ".socketApi";
    } else if( Utility::isLinux() || Utility::isBSD() ) {
        QString runtimeDir;
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
        runtimeDir = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation);
#else
        runtimeDir = QFile::decodeName(qgetenv("XDG_RUNTIME_DIR"));
        if (runtimeDir.isEmpty()) {
            runtimeDir = QDir::tempPath() + QLatin1String("/runtime-")
                + QString::fromLocal8Bit(qgetenv("USER"));
            QDir().mkdir(runtimeDir);
        }
#endif
        socketPath = runtimeDir + "/" + Theme::instance()->appName() + "/socket";
    } else {
	DEBUG << "An unexpected system detected";
    }

    SocketApiServer::removeServer(socketPath);
    QFileInfo info(socketPath);
    if (!info.dir().exists()) {
        bool result = info.dir().mkpath(".");
        DEBUG << "creating" << info.dir().path() << result;
        if( result ) {
            QFile::setPermissions(socketPath,
                                  QFile::Permissions(QFile::ReadOwner+QFile::WriteOwner+QFile::ExeOwner));
        }
    }
    if(!_localServer.listen(socketPath)) {
        DEBUG << "can't start server" << socketPath;
    } else {
        DEBUG << "server started, listening at " << socketPath;
    }

    connect(&_localServer, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));

    // folder watcher
    connect(FolderMan::instance(), SIGNAL(folderSyncStateChange(Folder*)), this, SLOT(slotUpdateFolderView(Folder*)));
    connect(ProgressDispatcher::instance(), SIGNAL(jobCompleted(QString, const SyncFileItem &)),
            SLOT(slotJobCompleted(QString, const SyncFileItem &)));
    connect(ProgressDispatcher::instance(), SIGNAL(syncItemDiscovered(QString, const SyncFileItem &)),
            this, SLOT(slotSyncItemDiscovered(QString, const SyncFileItem &)));
}
Ejemplo n.º 5
0
DebuggerPerlDBGP::DebuggerPerlDBGP(LanguageSettings* langs)
    : AbstractDebugger(langs), m_name("perldbgp"), m_isRunning(false), m_isJITActive(false),
      m_listenPort(-1), m_currentExecutionPoint(0), m_globalExecutionPoint(0), 
      m_pdbgSettings(0), m_net(0)
{
  m_pdbgSettings = new PerlDBGPSettings(Protoeditor::self()->settings()->configFile(),
      name(), label(), langSettings());

  langSettings()->registerDebuggerSettings(name(), m_pdbgSettings);

  m_currentExecutionPoint = new DebuggerExecutionPoint();
  m_globalExecutionPoint  = new DebuggerExecutionPoint();


  connect(Protoeditor::self()->settings(), SIGNAL(sigSettingsChanged()),
          this, SLOT(slotSettingsChanged()));

  m_net = new PerlDBGPNet(this);
  connect(m_net, SIGNAL(sigStarted()), this, SLOT(slotStarted()));
  connect(m_net, SIGNAL(sigClosed()), this, SLOT(slotStopped()));
  connect(m_net, SIGNAL(sigError(const QString&)), this, SIGNAL(sigInternalError(const QString&)));
  connect(m_net, SIGNAL(sigStepDone()), this, SLOT(slotStepDone()));
  connect(m_net, SIGNAL(sigNewConnection()), this, SLOT(slotNewConnection()));
  //connect(m_net, SIGNAL(sigBreakpoint()), this, SLOT(slotBreakpoint()));  
}
Ejemplo n.º 6
0
Simulator::Simulator() : QMainWindow()
{
	setWindowTitle("Simulator");

	logger = Logger::instance();

	robotView = new RobotView();
	robotView->fitInView(0, 0, 10, 10);
	setCentralWidget(robotView);

	logWidget = new LogWidget();
// 	addDockWidget(Qt::BottomDockWidgetArea, logWidget);

	robotControls = new RobotControls();
	addDockWidget(Qt::RightDockWidgetArea, robotControls);

	robotScene = new RobotScene(robotControls);
	robotView->setScene(robotScene);

	config = Configuration::instance();

	tcpServer = new QTcpServer(this);
	if(!tcpServer->listen(QHostAddress::Any, config->getCanServerPort()))
		abort("Simulator::Simulator(): Could not open canServer on port %d, exiting.", config->getCanServerPort());

	connect(tcpServer, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
}
Ejemplo n.º 7
0
AbstractServer::AbstractServer(QObject *parent)
     : QTcpServer(parent)

 {
     qDebug() << tr("AbstractServer::AbstractServer# Server created ") << endl;
	 connect(this, SIGNAL(newConnection()), 
            this,         SLOT(slotNewConnection()));
 }
Ejemplo n.º 8
0
void TCPServer::listen (quint16 port)
{
    m_server = new QTcpServer ();
    if(!m_server->listen (QHostAddress::Any, port)) qDebug() << "Failed to start listening...";
    else {
        qDebug() << QString("The server is listening on port %1").arg(m_server->serverPort ());
        connect(m_server, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
    }
}
Ejemplo n.º 9
0
NetworkServer::NetworkServer(const QString& networkPort) : Port()
{
    mAddress.setAddress(networkPort.section(":", 0, 0));
    mPort = networkPort.section(":", 1, 1).toInt();

    qDebug() << "NetworkServer::NetworkServer: listening on" << mAddress.toString() << ":" << mPort;

    mTcpServer = new QTcpServer(this);
    connect(mTcpServer, SIGNAL(newConnection()), SLOT(slotNewConnection()));
    mTcpServer->listen(mAddress, mPort);
}
Ejemplo n.º 10
0
Server::Server(int nPort) :  m_nNextBlockSize(0), scanner(fileName)
{
    m_ptcpServer = new QTcpServer(this);

    if (!m_ptcpServer->listen(QHostAddress::Any, nPort))
    {
        m_ptcpServer->close();
        return;
    }
    connect(m_ptcpServer, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
}
Ejemplo n.º 11
0
StatusApi::StatusApi()
    : QWebSocketServer("Cantata", NonSecureMode)
{
    connect(this, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
    connect(MPDConnection::self(), SIGNAL(statusUpdated(MPDStatusValues)), this, SLOT(statusUpdated(MPDStatusValues)));
    connect(MPDConnection::self(), SIGNAL(currentSongUpdated(Song)), this, SLOT(currentSongUpdated(Song)));
    connect(this, SIGNAL(currentSong()), MPDConnection::self(), SLOT(currentSong()));
    connect(this, SIGNAL(setConsume(bool)), MPDConnection::self(), SLOT(setConsume(bool)));
    connect(this, SIGNAL(setRandom(bool)), MPDConnection::self(), SLOT(setRandom(bool)));
    connect(this, SIGNAL(setRepeat(bool)), MPDConnection::self(), SLOT(setRepeat(bool)));
    connect(this, SIGNAL(setSingle(bool)), MPDConnection::self(), SLOT(setSingle(bool)));
    listen();
}
Ejemplo n.º 12
0
InformerTCPServer::InformerTCPServer(int nPort)
{
    m_ptcpServer = new QTcpServer(0);
    if(!m_ptcpServer->listen(QHostAddress::Any, nPort)){
        //пишем ошибку что порт не открылся

        m_ptcpServer->close();
        return;
    }

   connect(m_ptcpServer, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));


}
Ejemplo n.º 13
0
CProxy::CProxy( QObject * parent, const QString & listenHost, 
                              quint16 listenPort, 
                              const QString & connectHost, 
                              quint16 connectPort )
: QTcpServer( parent )
{
    m_clientHost = connectHost;
    m_clientPort = connectPort;
    connect( this, SIGNAL(newConnection()), this, SLOT(slotNewConnection()) );
    bool res = false;
    if ( listenHost.length() > 0 )
        res = listen( QHostAddress( listenHost ), listenPort );
    else
        res = listen( QHostAddress::Any, listenPort );

    QLOG_INFO() << "listen() result: " << ( res ? "true" : "false" );
}
Ejemplo n.º 14
0
my_server::my_server(int nPort, QWidget* pwgt /*=0*/) : QWidget(pwgt), m_nNextBlockSize(0)
{
    m_ptcpServer = new QTcpServer(this);
    if (!m_ptcpServer->listen(QHostAddress::Any, nPort)) {
        QMessageBox::critical(0,
                              "Server Error",
                              "Unable to start the server:"
                              + m_ptcpServer->errorString()
                              );
        m_ptcpServer->close();
        qDebug() << "ERROR started on port " + QString::number(nPort);
        return;
    }
    connect(m_ptcpServer, SIGNAL(newConnection()), this, SLOT(slotNewConnection()) );

    QMessageBox::information(0, "Server Started !" , "Server started on port " + QString::number(nPort));

}
Ejemplo n.º 15
0
void MyServer::startServer(){
    qDebug("Start server");

    if (isListening()){
        qDebug()<<"close server";
        close();
    }
    loadFile();
    printDictionary(dictionary);

    if (!listen(QHostAddress::Any, nPort)){
        qDebug()<<"Unable to start Server:"<<errorString();
        close();
        return;
    }
    connect(this, SIGNAL(newConnection()),this,SLOT(slotNewConnection()));
    qDebug() << isListening() << "TCPSocket listen on port" << nPort;
}
Ejemplo n.º 16
0
MyServer::MyServer(int nPort, QWidget* pwgt) : QWidget (pwgt), nextBlockSize(0), version(0)
{
    tcpServer = new QTcpServer(this);

    if ( !tcpServer->listen(QHostAddress::Any, nPort)) {

        QMessageBox::critical(0, "Server Error", "Unable to start the server:" + tcpServer->errorString ());
        tcpServer->close ( );
        return;
    }

    connect (tcpServer, SIGNAL (newConnection() ) , this, SLOT (slotNewConnection()));

    sdb = QSqlDatabase::addDatabase("QSQLITE");
    sdb.setDatabaseName(QCoreApplication::applicationDirPath() + "/project2.sqlite");

    QVBoxLayout* pvbxLayout = new QVBoxLayout;
    pvbxLayout->addWidget(new QLabel("<H1>Server</H1>")) ;
    setLayout(pvbxLayout);
}
Ejemplo n.º 17
0
Server::Server (int nPort, QWidget* pwgt) :
	QWidget(pwgt), NextBlockSize(0)
{
	this->nPort = nPort;
	ptcpServer = new QTcpServer(this);
	if (!ptcpServer->listen(QHostAddress::Any, nPort))
	{
		QMessageBox::critical(0, "Server Error", "Unable to start the server:" + ptcpServer->errorString());
		ptcpServer->close();
		return;
	}
	connect(ptcpServer, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
	ptxt = new QTextEdit;
	ptxt->setReadOnly(true);
	//Layout setup
	QVBoxLayout* pvbxLayout = new QVBoxLayout;
	pvbxLayout->addWidget(new QLabel("<H1>Server</H1>"));
	pvbxLayout->addWidget(ptxt);
	setLayout(pvbxLayout);
}
Ejemplo n.º 18
0
CGalconServer::CGalconServer(PortNumber portNumber, QWidget *parent) :
   QDialog(parent)
   ,ui(new Ui::CGalconServer)   
   , m_currentClientID(0)
{
   ui->setupUi(this);

   m_tcpServer = new QTcpServer(this);
   if (!m_tcpServer->listen(QHostAddress::Any, portNumber))
   {
      QMessageBox::critical(0,
      "Server Error",
      "Unable to start the server:"
      + m_tcpServer->errorString()
   );
   m_tcpServer->close();
   return;
   }
   connect(m_tcpServer, SIGNAL(newConnection()),
      this,SLOT(slotNewConnection()));
}
Ejemplo n.º 19
0
LibraryServer::LibraryServer(int port, QObject *parent) :
        QObject(parent),
        nextBlockSize(0)
{
    Server = new QTcpServer(this);

    if(!Server->listen(QHostAddress::Any, port)){
        QMessageBox::critical(
                    0,
                    QObject::tr("Server Error"),
                    QObject::tr("Unable to start server") + Server->errorString()
                    );
        Server->close();
        return;
    }
    else
        qDebug() << "Server created.";

    connect(Server, SIGNAL(newConnection()),
            this,   SLOT(slotNewConnection()));
 }
Ejemplo n.º 20
0
bool Server::startServer()
{
	ptcpServer = new QTcpServer(this);
	if (!ptcpServer->listen(QHostAddress::Any, nPort))
	{
		ptcpServer->close();
		emit signal_startServerError(ptcpServer->errorString());
		return false;
	}
	connect(ptcpServer, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
	emit signal_display(QString("Server started successfully!!!"));
	localServer = new QTcpServer(this);
	localPort = 8888;
	if (!localServer->listen(QHostAddress::LocalHost, localPort))
	{
		localServer->close();
		emit signal_startServerError(localServer->errorString());
		return false;
	}
	return true;
}
Ejemplo n.º 21
0
IOCPServer::IOCPServer(const QString& config_filename, 
                       FMCControl* fmc_control) :
    m_fmc_control(fmc_control)
{
    // setup config

    m_cfg = new Config(config_filename);
    MYASSERT(m_cfg != 0);
    setupDefaultConfig();
    m_cfg->loadfromFile();
    m_cfg->saveToFile();

    m_tcp_server = new QTcpServer;
    MYASSERT(m_tcp_server != 0);
    MYASSERT(connect(m_tcp_server, SIGNAL(newConnection()), this, SLOT(slotNewConnection())));

    if (!m_tcp_server->listen(QHostAddress::Any, m_cfg->getIntValue(CFG_TCP_PORT)))
        Logger::log(QString("IOCPServer: could not open TCP server on port %1").arg(m_cfg->getIntValue(CFG_TCP_PORT)));
    else
        Logger::log(QString("IOCPServer: TCP server listening on port %1").arg(m_cfg->getIntValue(CFG_TCP_PORT)));
}
Ejemplo n.º 22
0
MyServer::MyServer(int port, QWidget *parent) : QWidget(parent), shipCounter(0), shipIndexCounter(0)
{
    server = new QTcpServer(this);
    if(!server->listen(QHostAddress::Any , port)){
        messageLabel -> setText("Port error");
        server->close();
        return;
    }

    isClientConnected = false;

    qsrand(QTime::currentTime().msec());
    screen = QApplication::desktop()->screenGeometry();

    connect(server, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));

    createGui();

    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(sendAllData()));

}
Ejemplo n.º 23
0
DebuggerGB::DebuggerGB(DebuggerManager* manager)
    : AbstractDebugger(manager), m_name("Gubed"), m_isRunning(false), m_isJITActive(false),
      m_listenPort(-1), m_currentExecutionPoint(0), m_globalExecutionPoint(0), 
      m_gbSettings(0), m_net(0)
{
  m_currentExecutionPoint = new DebuggerExecutionPoint();
  m_globalExecutionPoint = new DebuggerExecutionPoint();

  m_gbSettings = new GBSettings(m_name);

  ProtoeditorSettings::self()->registerDebuggerSettings(m_gbSettings, m_name);

  connect(ProtoeditorSettings::self(), SIGNAL(sigSettingsChanged()),
          this, SLOT(slotSettingsChanged()));

  m_net = new GBNet(this);
  connect(m_net, SIGNAL(sigGBStarted()), this, SLOT(slotGBStarted()));
  connect(m_net, SIGNAL(sigGBClosed()), this, SLOT(slotGBClosed()));
  connect(m_net, SIGNAL(sigError(const QString&)), this, SIGNAL(sigInternalError(const QString&)));
  connect(m_net, SIGNAL(sigStepDone()), this, SLOT(slotStepDone()));
  connect(m_net, SIGNAL(sigNewConnection()), this, SLOT(slotNewConnection()));
}
Ejemplo n.º 24
0
RemoteMessage::RemoteMessage() : QLabel(),
    baResponce("<!doctype html>\n"
               "<html>\n"
               "<head>\n"
               "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">\n"
               "<title>" + qAppName().toUtf8() + "</title>\n"
                                                 "<style type=\"text/css\">\n"
                                                 ".f{float:left;}\n"
                                                 ".b{font-size:" WEB_FONTSIZE "px;width:" WEB_SIZE "px;height:" WEB_SIZE "px;}\n"
                                                                                                                         "</style>\n"
                                                                                                                         "</head>\n"
                                                                                                                         "<body>\n"
                                                                                                                         "<form action=\"command\" method=\"post\" enctype=\"text/plain\">\n"
                                                                                                                         "<div style=\"text-align: center\">\n"
                                                                                                                         "<input name=\"command\" style=\"width:25%\"><br />\n"
                                                                                                                         "<input type=\"submit\" value=\"RUN\">\n"
                                                                                                                         "</div>\n"
                                                                                                                         "</form>\n"
                                                                                                                         "<br /><br />\n"),
    baFavicon(QByteArray::fromRawData(
                  "HTTP/1.1 200 OK\r\n"
                  "Content-Type: image/x-icon\r\n"
                  "Cache-Control: max-age=86400\r\n"
                  "Content-Length: 1150\r\n"
                  "\r\n"
                  "\x00\x00\x01\x00\x01\x00\x10\x10\x00\x00\x01\x00\x20\x00\x68\x04\x00\x00\x16\x00"
                  "\x00\x00\x28\x00\x00\x00\x10\x00\x00\x00\x20\x00\x00\x00\x01\x00\x20\x00\x00\x00"
                  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
                  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x23\x23\x23\x1F\x5F\x5F\x5F\xF0\x69\x69"
                  "\x69\xF4\x68\x68\x68\xF4\x68\x66\x65\xF6\x67\x64\x62\xF9\x68\x65\x63\xF9\x6A\x68"
                  "\x68\xF7\x6C\x6C\x6C\xF5\x6D\x6D\x6D\xF5\x6E\x6E\x6E\xF6\x6F\x6F\x6F\xF6\x70\x70"
                  "\x70\xF6\x8C\x8C\x8C\xB8\x00\x00\x00\x00\x00\x00\x00\x00\x12\x12\x12\x97\xFB\xFC"
                  "\xFC\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
                  "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
                  "\xFF\xFF\xFF\xFF\xFF\xFF\x71\x71\x71\xF5\x00\x00\x00\x00\x00\x00\x00\x00\x1F\x17"
                  "\x11\xB1\xFF\xFF\xFF\xFF\x30\x2F\x2E\xFF\x19\x1A\x1A\xFF\x1D\x1E\x1E\xFF\x1D\x1D"
                  "\x1E\xFF\x1C\x1C\x1D\xFF\x23\x23\x24\xFF\x2D\x2D\x2D\xFF\x35\x36\x36\xFF\x3E\x3E"
                  "\x3F\xFF\x40\x40\x40\xFF\xFF\xFF\xFF\xFF\x72\x72\x72\xF4\x00\x00\x00\x00\x42\x24"
                  "\x0A\x17\x34\x1D\x0E\xFC\xFF\xFF\xFF\xFF\x32\x31\x30\xFF\x13\x13\x13\xFF\x18\x18"
                  "\x18\xFF\x19\x19\x19\xFF\x1A\x1A\x1A\xFF\x19\x19\x19\xFF\x18\x18\x18\xFF\x21\x21"
                  "\x21\xFF\x2A\x2A\x2A\xFF\x27\x27\x27\xFF\xFF\xFF\xFF\xFF\x73\x73\x73\xF2\x00\x00"
                  "\x00\x00\x57\x2E\x0D\xD2\x46\x2A\x18\xFF\xFF\xFF\xFF\xFF\x2B\x2B\x2A\xFF\x13\x13"
                  "\x13\xFF\x00\x00\x00\xFF\x00\x00\x00\xFF\x00\x00\x00\xFF\x06\x06\x06\xFF\x06\x06"
                  "\x06\xFF\x07\x07\x07\xFF\x06\x06\x06\xFF\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\x74\x74"
                  "\x74\xF1\x45\x1F\x06\x10\x78\x5A\x43\xFE\x50\x32\x1A\xFF\xFF\xFF\xFF\xFF\x1E\x1D"
                  "\x1B\xFF\x0F\x0F\x0F\xFF\x0B\x0B\x0B\xFF\xFC\xFC\xFC\xFF\xF8\xF8\xF8\xFF\x00\x00"
                  "\x00\xFF\x00\x00\x00\xFF\x00\x00\x00\xFF\x00\x00\x00\xFF\x00\x00\x00\xFF\xFF\xFF"
                  "\xFF\xFF\x75\x75\x75\xF0\x5D\x36\x1A\x77\xA3\x91\x83\xFF\x52\x34\x1B\xFF\xFF\xFF"
                  "\xFF\xFF\x15\x13\x12\xFF\xFB\xFB\xFB\xFF\x2D\x2D\x2D\xFF\x22\x22\x22\xFF\x2D\x2D"
                  "\x2D\xFF\x21\x21\x21\xFF\x09\x09\x09\xFF\x00\x00\x00\xFF\x00\x00\x00\xFF\x00\x00"
                  "\x00\xFF\xFF\xFF\xFF\xFF\x77\x75\x74\xF2\x61\x3A\x1B\xB5\x88\x66\x4A\xFF\x55\x37"
                  "\x1F\xFF\xFF\xFF\xFF\xFF\x0E\x0E\x0D\xFF\x1F\x1F\x1F\xFF\xFD\xFD\xFD\xFF\x27\x27"
                  "\x27\xFF\x37\x37\x37\xFF\x42\x42\x42\xFF\x4E\x4E\x4E\xFF\x51\x51\x51\xFF\x4D\x4D"
                  "\x4D\xFF\x39\x39\x3A\xFF\xFF\xFF\xFF\xFF\x77\x74\x72\xF6\x62\x3B\x1D\xB5\x77\x4A"
                  "\x27\xFF\x57\x3B\x22\xFF\xFF\xFF\xFF\xFF\x03\x02\x01\xFF\xFB\xFB\xFB\xFF\x06\x06"
                  "\x06\xFF\x16\x17\x17\xFF\x25\x25\x25\xFF\x2F\x2F\x2F\xFF\x3A\x3A\x3A\xFF\x45\x45"
                  "\x45\xFF\x4F\x4F\x4F\xFF\x54\x55\x55\xFF\xFF\xFF\xFF\xFF\x7C\x78\x76\xF6\x60\x38"
                  "\x1D\x79\x70\x44\x26\xFF\x57\x3A\x23\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
                  "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
                  "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x84\x82"
                  "\x81\xF2\x42\x24\x04\x13\x5E\x36\x18\xFE\x84\x50\x28\xFF\x7C\x71\x68\xFF\x91\x91"
                  "\x8E\xFF\x96\x93\x92\xFF\x97\x94\x93\xFF\x97\x95\x92\xFF\x97\x95\x93\xFF\x8F\x88"
                  "\x82\xFF\x93\x8D\x8A\xFF\x8D\x86\x80\xFF\x86\x7E\x76\xFF\x89\x85\x82\xFF\x71\x6A"
                  "\x63\xFE\xB3\xB4\xB4\x5A\x00\x00\x00\x00\x58\x30\x10\xD6\x73\x47\x22\xFF\xA9\x83"
                  "\x61\xFF\xC1\xA2\x89\xFF\xDD\xCE\xC1\xFF\xEB\xDE\xD3\xFF\xD8\xB6\x96\xFF\xDE\xC0"
                  "\xA5\xFF\xEB\xDB\xCC\xFF\xED\xE2\xD9\xFF\xE3\xD7\xCE\xFF\xDC\xD3\xCC\xFF\xBA\xAB"
                  "\x9F\xFF\x5A\x2F\x0D\xCC\x00\x00\x00\x00\x00\x00\x00\x00\x4C\x23\x0D\x1A\x58\x32"
                  "\x13\xFA\x94\x6D\x4D\xFF\xD0\xBA\xA8\xFF\xDB\xCE\xC3\xFF\xDD\xCD\xBE\xFF\xE6\xDB"
                  "\xD1\xFF\xEA\xE1\xD7\xFF\xE1\xD1\xC3\xFF\xE7\xE2\xDD\xFF\xE7\xE1\xDC\xFF\xDC\xD6"
                  "\xD1\xFF\x76\x56\x3D\xFA\x59\x2F\x0E\x12\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
                  "\x00\x00\x4E\x2C\x06\x53\x56\x30\x10\xFA\xAE\x93\x7E\xFF\xF0\xE8\xE2\xFF\xF3\xEF"
                  "\xEB\xFF\xF0\xEC\xE8\xFF\xF3\xF1\xEE\xFF\xF4\xF2\xF1\xFF\xF8\xF7\xF7\xFF\xEC\xE8"
                  "\xE7\xFF\x82\x67\x51\xFA\x53\x2B\x07\x48\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
                  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x4D\x23\x0D\x1A\x51\x2B\x09\xD5\x7C\x5F"
                  "\x48\xFE\xD4\xC8\xBD\xFF\xF4\xF1\xED\xFF\xFF\xFF\xFF\xFF\xEA\xE6\xE3\xFF\xB9\xAC"
                  "\xA0\xFE\x65\x40\x23\xD3\x4B\x2B\x0E\x14\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
                  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
                  "\x00\x00\x4E\x29\x0A\x12\x2E\x1B\x0D\xA6\x66\x40\x20\xB5\x64\x3C\x1E\xB2\x2C\x1B"
                  "\x0E\xA2\x4E\x2A\x0B\x0E\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
                  "\x00\x00\x00\x00\x00\x00\xC0\x00\x00\x00\xC0\x00\x00\x00\xC0\x00\x00\x00\x80\x00"
                  "\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
                  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x01\x00\x00\x80\x01\x00\x00\xC0\x03"
                  "\x00\x00\xE0\x07\x00\x00\xF8\x1F\x00", 1249)),
    bValid(true)
{
    Q_ASSERT(sizeof(quint16) == sizeof(ushort));

    const QString strAppName = qAppName(),
            strAppDir = qApp->applicationDirPath();
    QTranslator translator;
    if (translator.load(strAppName, strAppDir) || translator.load(strAppName + '_' + QLocale::system().name(), strAppDir))
        qApp->installTranslator(&translator);

    QHostAddress hAddr(QHostAddress::AnyIPv4);
    quint16 iPort = 0;

    //arguments
    const QStringList slistArgs = qApp->arguments();
    if (slistArgs.size() > 1)
    {
        const QString &strArg = slistArgs.at(1);
        const int iLeft = strArg.indexOf(':', 7);        //[7 = 0.0.0.0:]
        if (iLeft < 0)
        {
            bValid = false;
            QMessageBox::critical(0, 0, "Incorrect parameter");
            return;
        }

        bool bOk;
        iPort = strArg.midRef(iLeft+1).toUShort(&bOk);
        if (!(bOk && hAddr.setAddress(strArg.left(iLeft))))
        {
            bValid = false;
            QMessageBox::critical(0, 0, "Incorrect parameter");
            return;
        }
    }

    tcpServer = new QTcpServer(this);
    if (!tcpServer->listen(hAddr, iPort))
    {
        bValid = false;
        QMessageBox::critical(0, 0, "Don't run server: " + hAddr.toString() + ':' + QString::number(iPort) + '\n' + tcpServer->errorString());
        return;
    }

    //settings
    int iRules = 0;
    QFile file(strAppDir + '/' + strAppName + ".cfg");
    if (file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        const QStringList slistRules = QString(file.readAll()).split('\n', QString::SkipEmptyParts);
        if (!file.error())
            for (int i = 0, iDelim; i < slistRules.size(); ++i)
            {
                iDelim = slistRules.at(i).indexOf('|');
                if (iDelim > 0 && slistRules.at(i).lastIndexOf('|') == iDelim)
                {
                    baResponce += "<form action=\"" + QByteArray::number(iRules++) + "\" method=\"post\" enctype=\"text/plain\" class=\"f\">\n"
                                                                                     "<div><input type=\"submit\" value=\"" + slistRules.at(i).left(iDelim).toHtmlEscaped() + "\" class=\"b\"></div>\n"
                                                                                                                                                                              "</form>\n";
                    slistEntries.append(slistRules.at(i).mid(iDelim+1));
                }
            }
        file.close();
    }
    baResponce += "</body>\n</html>\n";
    baResponce.prepend("HTTP/1.1 200 OK\r\n"
                       "Content-Type: text/html\r\n"
                       "Cache-Control: no-cache\r\n"
                       "Content-Length: " + QByteArray::number(baResponce.length())  + "\r\n\r\n");

    this->setAlignment(Qt::AlignCenter);
    this->setText("Server: " + hAddr.toString() + ':' + QString::number(tcpServer->serverPort()) +
                  "\nRules: " + QString::number(iRules));
    this->setFixedSize(250, 50);

    //connects
    connect(tcpServer, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));

    //settings
    this->restoreGeometry(QSettings("UserPrograms", strAppName).value("Geometry").toByteArray());
}
Ejemplo n.º 25
0
void server::CreatorConnections()
{
    connect(m_ptcpServer, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
}