123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- #ifndef CLIENT_H
- #define CLIENT_H
- #include <string>
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/socket.h>
- #include <arpa/inet.h>
- #include <sys/time.h>
- #include <math.h>
- #include <string.h>
- #include <unistd.h>
- #include <QDebug>
- #include <QThread>
- #include <time.h>
- const int KUniform = 0;
- const int KPoisson = 1;
- const int KBinomial = 2;
- const int KExponential = 3;
- #define DATA_LEN 1000
- class SANClient : public QThread
- {
- Q_OBJECT
- private:
- struct sockaddr_in iServAddr;
- int iClientSockFd;
- FILE *iFp;
- int iPort;
- std::string iIp;
- int iDistribution;
- double iSendRate;
- long long iCount;
- double iTotDelay;
- protected:
- virtual void run(void);
- public:
- //ctor
- SANClient();
- //dtor
- ~SANClient();
- public:
- //functions
- void SetDestnPort(int aPort);
- void SetDestnIp(std::string aIp);
- bool OpenFile(std::string aFileName);
- bool SetupConnection();
- bool ConnectToServer();
- void SendData();
- bool ReceiveData();
- void SetDistribution(int aDistribution);
- int GetDistribution();
- void SetSendRate(int aSendRate);
- int GetSendRate();
- int GetCount();
- void SetDelay(double aDelay);
- long double GetTotDelay();
- unsigned long iUSleep;
- signals:
- void EmitClientConnected(bool aStatus);
- void EmitDataSent(char *aBuf);
- };
- class SANReceive : public QThread
- {
- Q_OBJECT
- private:
- int iPort;
- char *iBuf;
- int iLen;
- struct sockaddr_in iClientAddr;
- int iServSockFd, iBlankSockFd;
- long long iCount;
- protected:
- virtual void run(void);
- public:
- //ctor
- SANReceive();
- //dtor
- ~SANReceive();
- public:
- //functions
- void SetPort(int aPort);
- int GetPort();
- bool SetupConnection();
- bool StartServer();
- int AcceptConnections();
- void RecvData();
- int GetCount();
- signals:
- void EmitClientAccepted(bool aStatus);
- void EmitServerStart(bool aStatus);
- void EmitDisplaySortedData(QString);
- };
- #endif // CLIENT_H
|