automating or running a process back



  • Hi everyone
    I would like to automate sending SMS with an application i am writting but i don't how i to do it. My application must be connected to a server from where it get informations to send via SMS. I am wondering how to create for example a class that inherit QMainWindow and run a process that will check the status of the connection with the server, get information from the server and and send them via mail or SMS every 5 minutes.

    I resume the fonctioning :

    • Create a QMainWindow object
    • Connect to the server and a SMS modem
    • Check the status of the connection
    • Send commands and Receive informations
    • Send the information via SMS
    • And update information sent status

  • Moderators

    @Network1618033 For networking start here: http://doc.qt.io/qt-5/qtnetwork-index.html
    You can take a look at examples provided with Qt.



  • @jsulm thank for your answer. i forgot something. I'm using QtTelnet (Github) class to establish connection between my application and the server. That works fine. Now i'm looking to check the status and send my commands, receive answer(informations) and send them every 5 minutes.


  • Moderators

    @Network1618033 said in automating or running a process back:

    QtTelnet

    I never used it and I'm not sure why you use insecure Telnet to connect to the server. But QtTelnet has documentation.



  • @jsulm Telnet was the solution my teacher suggest me but i am at your disposal for any other solution that can be secured and easy :) . Otherwise I think you have not understand my problem. It is the automating my problem. Should i use a loop (if it is possible) for example or there is an design pattern that permit me run a code that will check my connection state, communicate with my server and send the SMS.



  • @Network1618033

    Once the server is setup and listening on the sms port grab the datastream from a Qbytearray. Check the first two bytes in the data stream this will be your Opcode or Packetheader..

    qbytearray recvbuff;
    //get the first 2 bytes in the packet
    
    //now handling those two bytes or qstring or std:: message
    quint16 opcode;
    switch(opcode) 
    {
        case ErrorConnection : cout << 'message'; // 
                 break;       // exits the switch
        case LoginSuccessful : cout << 'messge';
                 break;
        case BadLogin : cout << 'message';
                 break;
    }
    

    Check the status of the connection - Should be a event handler for this to check the State and return it.
    Send commands and Receive informations - Send function that sends it to the client or server. Recv side see code.
    Send the information via SMS - Send it from the server with a send method.
    And update information sent status - Create a signal and slot with a timer and a function that sends it base of time.

    Could try QtHttp and do it over http or Qtcp



  • This post is deleted!


  • @Sunfluxgames Thanks i'm going try what you explaned. Someone talk me also about Qthread that can permit me run process back. Is it a good idea to ?



  • (windows or linux)????

    Are you automating the client and server or just server. If this is so I would create a expect script batch file to run a client.

    Server wise..

    Main.cpp

    #include <QCoreApplication>
    #include "mytcpserver.h"
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
        
        // create MyTcpServer
        // MyTcpServer constructor will create QTcpServer
    
        MyTcpServer server;
    
        return a.exec();
    }
    

    mytcpserver.h:

    /#ifndef MYTCPSERVER_H
    #define MYTCPSERVER_H
    
    #include <QObject>
    #include <QTcpSocket>
    #include <QTcpServer>
    #include <QDebug>
    
    class MyTcpServer : public QObject
    {
        Q_OBJECT
    public:
        explicit MyTcpServer(QObject *parent = 0);
        
    signals:
        
    public slots:
        void newConnection();
    
    private:
        QTcpServer *server;
    };
    
    #endif // MYTCPSERVER_H
    

    mytcpserver.cpp:

    /#include "mytcpserver.h"
    
    MyTcpServer::MyTcpServer(QObject *parent) :
        QObject(parent)
    {
        server = new QTcpServer(this);
    
        // whenever a user connects, it will emit signal
        connect(server, SIGNAL(newConnection()),
                this, SLOT(newConnection()));
    
       unsigned int port = 2222 //sms port
    
        if(!server->listen(QHostAddress::Any, port))
        {
            //"Server could not start";
        }
        else
        {
            //"Server started!";
        }
    }
    
    void MyTcpServer::newConnection()
    {
        // need to grab the socket
        QTcpSocket *socket = server->nextPendingConnection();
    
        QByteArray recvbuff;
    
    while(!recvbuff.contains('\n')) 
    {
        socket->waitForReadyRead();
        recvbuff += socket->readAll();
    }
     //A function to process client mesasge
    processTeleNetMessage(message);
    }
    
    void MyTcpServer::processTeleNetMessage(Qstring message)
    {
           //use a case system to do login process or Qstring Compare
          // send automated message read from a text file or just hardcode the message here.
          socket->write("eat a dick\r\n");
          socket->flush();
         socket->waitForBytesWritten(3000);
    
        /// when all done etc..  // disconnects client...
       socket->close();
    
    }
    

    Now if your doing this all in one application then yea you could use a Qthread to create events that loop thru all this processing. Really up to you and how you want to build this application.


  • Moderators

    @Network1618033 said in automating or running a process back:

    Otherwise I think you have not understand my problem

    That's true as your description is unclear.
    Please do not use QThread until you really know you really need them.
    Qt networking classes are asynchronous, so there is usually no need for threads.
    To me it is not really clear what your question/problem actually is.
    "Connect to the server and a SMS modem" - what modem is it and how do you connect to it?
    "Check the status of the connection" - again: what modem is it? How do you access it?
    "Send commands and Receive informations" - what commands? What information? Send/receive to/from where (modem)?
    "Send the information via SMS" - depends on the way you access the modem.
    "And update information sent status" - update where?



  • This post is deleted!


  • @jsulm

    OK i'm going explan clearly !.

    I have a BSC(Base Station Controller) that permit to manage failure on GSM equipements(BTS - Base Tranceiver Station - , Links , TRX) connected to it. Informations about Failures can be get from the BSC by sending some commands (for example "ls" on ubuntu that return the list of directories and files existing in the current directory). As the supervision Office is far from the BSC we can use telnet protocol to connect to it in order to send commands we want. In order to warn technicians of some possible failures i decided to automate "sending command to the server in order to receive the list of failures and send these failures via SMS" . I judged that if i want to send SMS with my application, a GSM modem is required. For this I thought that my application should work in the following way :

    • It must have a main window that show the current failures and their state (Sent or not)

    Behind this main window a process must execute the following task :

    • When starting , the application should attempt to connect to the different equipments (BSC, GSM modem).

    • If the connections failed the application should wait for them succeed or until the someone close the application.

    • If the connections succeeded the application should start sending commands every 5 minutes for examples in order to list failures and send them via SMS. Before every sending actions (sending commands or messages) the application must check the state of connection to the equipment in order to stuck in waiting and show the in main windows that there is a problem to connect to an equipment.

    • After sending SMS the application must update the state of failure sent

    I expect i have been more clear now !.
    Please excuse me for my spelling mistakes or grammatical error; I do not speak fluent English.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.