Beispiel #1
0
ServerInfo::ServerInfo( Q_UINT16 port, QWidget *parent, const char *name ) :
    ServerInfoBase( parent, name )
{
    SimpleServer *server = new SimpleServer( port, this, "simple server" );
    connect( server, SIGNAL(newConnect()), SLOT(newConnect()) );
    connect( btnQuit, SIGNAL(clicked()), qApp, SLOT(quit()) );
}
void MainWindow::prepareUi(){
    gt = new GTServer;

    connect(ui->startButton, SIGNAL(clicked()), this, SLOT(clickStart()));
    connect(ui->stopButton, SIGNAL(clicked()), this, SLOT(clickStop()));

    connect(gt, SIGNAL(signalNewConnect()), this, SLOT(newConnect()));
}
Beispiel #3
0
bool ServerInfo::qt_invoke( int _id, QUObject* _o )
{
    switch ( _id - staticMetaObject()->slotOffset() ) {
    case 0: newConnect(); break;
    default:
	return ServerInfoBase::qt_invoke( _id, _o );
    }
    return TRUE;
}
Beispiel #4
0
bool SimpleServer::qt_emit( int _id, QUObject* _o )
{
    switch ( _id - staticMetaObject()->signalOffset() ) {
    case 0: newConnect(); break;
    default:
	return QServerSocket::qt_emit(_id,_o);
    }
    return TRUE;
}
Beispiel #5
0
void logon::on_logonButton_clicked()
{
    //checkPwd();
    usrName=ui->usrLineEdit->text().trimmed(); //移除开头和结尾的空白字符
    pwd=ui->pwdLineEdit->text().trimmed();
    if(usrName==""||pwd=="")  //用户名或密码不能为空
          QMessageBox::warning(0, tr("Error"),tr("用户名或密码不能为空"), QMessageBox::Ok);
    else
         newConnect();
}
main()
{
    firstClient = NULL;        // Initialize the first element of the
    // linked-list to NULL
    // Initialize the WinSock library
    WSADATA wsaData;
    if (WSAStartup(0x101, &wsaData) != 0)
    {
        cout << "Error initializing WinSock library: " << WSAGetLastError() << endl;
        return 0;
    }

    try
    {
        // A named semaphore is created with an initial value of 1 (Unlock) and a
        // maximum value of 1.  The semaphore is used within the spawned threads
        // to protect the XPCClientConnection linked-list from multiple access
        XPCSemaphore listSem("LISTSEM", 1, 1);


        // New socket is created and bound to port #6572
        XPCTcpSocket SpawnServerSocket((long int)6572);
        SpawnServerSocket.vBindSocket();

        // Connections are listened for
        SpawnServerSocket.vListen(5);

        while(1)    // Loop forever
        {
            // Accept remote process connections.  When a remote process
            // connects an new XPCTcpSocket object is created.
            XPCTcpSocket *RemoteProcessSocket = SpawnServerSocket.Accept();

            // The newly created socket and the semaphore are placed within a
            // XPCConnectInfo object
            XPCConnectInfo *connectInfo = new XPCConnectInfo(RemoteProcessSocket, &listSem);

            // A thread is created dedicated to communicating with the
            // connected socket.  The thread is passed the connectInfo object
            XPCThread newConnect(processConnect, (void *)connectInfo);

        }
    }
    catch(XPCException &exceptObject)
    {
        // All semaphore, socket, and thread related exceptions are captured and
        // displayed
        cout << "SpawnServer Error: " << exceptObject.sGetException() << endl;
        return 1;
    }
}
Beispiel #7
0
void MainWindow::startTcpserver()
{
    ui->connectButton->setEnabled(false);
    ui->lineEdit->setEnabled(true);
    ui->sendButton->setEnabled(true);

    server = new QTcpServer(this);
    server ->listen(QHostAddress::Any, 19999);

    ui->textEdit->append("start server 127.0.0.1:19999");
    connect(server, SIGNAL(newConnection()), this, SLOT(newConnect()));

    isServer =1;
}
Beispiel #8
0
Mana::Mana(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Mana)
{
     ui->setupUi(this);
     m_canSendMsg = false;
     m_server = new QTcpServer(this);
     quint16 prot = 8763;
     m_server->listen(QHostAddress::Any,prot);
    connect(this->m_server,SIGNAL(newConnection()),this,SLOT(newConnect()));
    connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(sendMsg()));

    tcpSocket = new QTcpSocket();

}
Beispiel #9
0
int Widget::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: newConnect(); break;
        case 1: readMessage(); break;
        case 2: displayError((*reinterpret_cast< QAbstractSocket::SocketError(*)>(_a[1]))); break;
        case 3: on_pushButton_clicked(); break;
        default: ;
        }
        _id -= 4;
    }
    return _id;
}
Beispiel #10
0
Client::Client():
    m_hostAddr("192.168.1.25"),
    m_hostPort(12345)
{
    m_server = new QTcpServer(this);
    m_soket = new QTcpSocket();
    m_timer = new QTimer();
    m_timerCheckData = new QTimer();
    m_connectState = false;

    connect(m_timerCheckData,SIGNAL(timeout()),this,SLOT(noData()));
    connect(m_timer,SIGNAL(timeout()),this,SLOT(openConnection()));
    connect(m_soket,SIGNAL(connected()),this,SLOT(connected()));
    //connect(m_soket,SIGNAL(disconnected()),this,SLOT(disconnected()));
    connect(m_server,SIGNAL(newConnection()),this,SLOT(newConnect()));
    m_server->listen(QHostAddress::Any,m_hostPort);
    m_timer->start(1000);
    m_timerCheckData->start(105);

}
Beispiel #11
0
void TcpServer::newConnection( int socket )
{
	emit newConnect(socket);
}
Beispiel #12
0
// 连接按钮
void Client::on_connectButton_clicked()
{
    newConnect();
}
Beispiel #13
0
void SimpleServer::newConnection( int socket )
{
    (void)new ClientSocket( socket, &info, this, "client socket" );
    emit newConnect();
}
Beispiel #14
0
// 设置地址
void TcpClient::setHostAddress(QHostAddress address)
{
    hostAddress = address;
    newConnect();
}
void Widget::on_pushButton_clicked()//连接按钮
{
    newConnect();//请求连接
}
Beispiel #16
0
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    tcpclient = new TcpClient(this);
    movie = new QMovie(":/new/prefix1/image/fan_m40x40.gif");
    timer = new QTimer(this);
    ui->fan_vl->setMovie(movie);
    connect(tcpclient,SIGNAL(diplayMessage(QString)),this,SLOT(diplayMessage(QString)));
    connect(tcpclient,SIGNAL(displayValue(int,QString,QString)),this,SLOT(displayValue(int,QString,QString)));
    connect(this,SIGNAL(sendMessage(int,int,QString)),tcpclient,SLOT(sendMessage(int,int,QString)));
    connect(this,SIGNAL(newConnect()),tcpclient,SLOT(newConnect()));
    connect(timer, SIGNAL(timeout()), this, SLOT(qtimeSlot()));
    timer->start(20000);
    ui->label_ip->setText(getLocalIP());
    /*全局变量初始化*/
    textBrowser_flag = true;
    led_flag = true;
    fan_flag = true;
    led_show_flag = true;
    /*按键事件效果*/
    ui->pushButton_sensor->setStyleSheet("QPushButton{border-image: url(:/new/prefix1/image/sensor.png);}"
    "QPushButton:hover{border-image: url(:/new/prefix1/image/sensor.png);}"
    "QPushButton:pressed{border-image: url(:/new/prefix1/image/sensor_OutLight.png);}");
    ui->pushButton_debug->setStyleSheet("QPushButton{border-image: url(:/new/prefix1/image/debug.png);}"
    "QPushButton:hover{border-image: url(:/new/prefix1/image/debug.png);}"
    "QPushButton:pressed{border-image: url(:/new/prefix1/image/debug_OutLight.png);}");
    ui->pushButton_left->setStyleSheet("QPushButton{border-image: url(:/new/prefix1/image/left.png);}"
    "QPushButton:hover{border-image: url(:/new/prefix1/image/left.png);}"
    "QPushButton:pressed{border-image: url(:/new/prefix1/image/left_OutLight.png);}");
    ui->pushButton_right->setStyleSheet("QPushButton{border-image: url(:/new/prefix1/image/right.png);}"
    "QPushButton:hover{border-image: url(:/new/prefix1/image/right.png);}"
    "QPushButton:pressed{border-image: url(:/new/prefix1/image/right_OutLight.png);}");
    ui->pushButton_connect->setStyleSheet("QPushButton{border-image: url(:/new/prefix1/image/push_up.png);}"
    "QPushButton:hover{border-image: url(:/new/prefix1/image/push_up.png);}"
    "QPushButton:pressed{border-image: url(:/new/prefix1/image/push_down.png);}"
    "QPushButton{color: rgb(255, 255, 255);}");
    ui->pushButton_getip->setStyleSheet("QPushButton{border-image: url(:/new/prefix1/image/push_up.png);}"
    "QPushButton:hover{border-image: url(:/new/prefix1/image/push_up.png);}"
    "QPushButton:pressed{border-image: url(:/new/prefix1/image/push_down.png);}"
    "QPushButton{color: rgb(255, 255, 255);}");
    ui->pushButton_suspend->setStyleSheet("QPushButton{border-image: url(:/new/prefix1/image/push_up.png);}"
    "QPushButton:hover{border-image: url(:/new/prefix1/image/push_up.png);}"
    "QPushButton:pressed{border-image: url(:/new/prefix1/image/push_down.png);}"
    "QPushButton{color: rgb(255, 255, 255);}");
    ui->pushButton_clear->setStyleSheet("QPushButton{border-image: url(:/new/prefix1/image/push_up.png);}"
    "QPushButton:hover{border-image: url(:/new/prefix1/image/push_up.png);}"
    "QPushButton:pressed{border-image: url(:/new/prefix1/image/push_down.png);}"
    "QPushButton{color: rgb(255, 255, 255);}");

    ui->label_31->hide();
    ui->led_id->hide();
    ui->led_tp->hide();
    ui->led_vl->hide();
    ui->pushButton_led->hide();
    ui->widget2->setGeometry(410,0,375,311);

    int i;
    for(i = 0; i < 13; i ++)
        num_flag[i]=0;
}
Beispiel #17
0
void TcpClient::setHostAddress(QHostAddress address)  //设置服务器地址并连接服务器
{
    hostAddress = address;
    newConnect();
}