Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "client.h"
- #include <QHostAddress>
- Client::Client(QObject* parent): QObject(parent)
- {
- connect(&client, SIGNAL(connected()),
- this, SLOT(startTransfer()));
- LENGTH =8;
- }
- Client::~Client()
- {
- client.close();
- }
- void Client::start(QString address, quint16 port)
- {
- QHostAddress addr(address);
- client.connectToHost(addr, port);
- }
- void Client:: Read(QString filename)
- {
- QFile mfile(filename);
- if(!mfile.open(QFile::ReadOnly | QFile::Text))
- {
- qDebug() << "Could Not Open File For Reading!";
- return;
- }
- QTextStream in(&mfile);
- //QByteArray ba;
- while (!in.atEnd()) {
- line = in.readAll();
- qDebug() << line;
- }
- mfile.close();
- }
- void Client::startTransfer()
- {
- QString mfilename ="/home/ddm/Desktop/ENV_1_M2000.csv";
- Read(mfilename);
- QByteArray ba = line.toLocal8Bit();
- c_str2 = ba.data();
- client.write(c_str2,2048);
- }
- #include "myserver.h"
- MyServer::MyServer(QObject *parent) :
- QTcpServer(parent)
- {
- }
- void MyServer :: StartServer()
- {
- QHostAddress myAddr=QHostAddress("192.168.3.2");
- if(!this->listen(myAddr,7350))
- {
- qDebug() << "Could not start server";
- }
- else
- {
- qDebug() << "Listening...";
- }
- }
- void MyServer :: incomingConnection(int socketDescriptor)
- {
- qDebug()<<socketDescriptor<<"Connecting...";
- MyThread *thread = new MyThread(socketDescriptor,this);
- connect(thread,SIGNAL(finished()),thread,SLOT(deleteLater()));
- thread ->start();
- }<br/>
- #include "mythread.h"
- #include<QList>
- #include <QFile>
- #include <QString>
- #include <QtDebug>
- #include <QTextStream>
- #include <QBitArray>
- #include<QStringList>
- #include <GL/glu.h>
- #include <GL/glut.h>
- #define LENGTH 80
- MyThread::MyThread(int ID,QObject *parent) :
- QThread(parent)
- {
- this ->socketDescriptor = ID;
- ROWS=100;
- COLS=6;
- row=0;col=0;
- }
- void MyThread::run()
- {
- //thread starts here
- qDebug()<< socketDescriptor <<"Starting thread";
- socket = new QTcpSocket;
- if(!socket->setSocketDescriptor(this->socketDescriptor))
- {
- emit error(socket->error());
- return;
- }
- connect(socket,SIGNAL(readyRead()),this,SLOT(readyRead()), Qt::DirectConnection);
- connect(socket,SIGNAL(disconnected()),this,SLOT(disconnected()),Qt::DirectConnection);
- qDebug()<< socketDescriptor <<"Client connected";
- exec();
- }
- void MyThread :: readyRead()
- {
- float array[ROWS][COLS];
- QByteArray Data = socket ->readAll();
- QString str(Data);
- qDebug()<< socketDescriptor <<"Data in:" <<row<<Data;
- QStringList tempCN = str.split("n");
- qDebug()<<"tempCN="<<tempCN;
- for(int i=0;i<40;i++)
- {
- QStringList tempCN1 = tempCN[i].split(",");
- qDebug()<<"tempCN1["<<i<<"]="<<tempCN1;
- array[i][0] = QString(tempCN1[0]).toFloat();
- array[i][1] = QString(tempCN1[1]).toFloat();
- array[i][2] = QString(tempCN1[2]).toFloat();
- array[i][3] = QString(tempCN1[3]).toFloat();
- array[i][4] = QString(tempCN1[4]).toFloat();
- array[i][5] = QString(tempCN1[5]).toFloat();
- }
- for(int i=0;i<40;i++)
- {
- for(int j=0;j<6;j++)
- {
- qDebug()<<"array["<<i<<"]"<<"["<<j<<"]"<<array[i][j];
- }
- }
- row++;
- /* col++*/;
- }
- void MyThread :: disconnected()
- {
- qDebug()<< socketDescriptor <<"Disconnected";
- socket->deleteLater();
- exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement