MyClient::MyClient()
{
actions = 0;
theLayout->addWidget(portNumberUDP,0,2);
theLayout->addWidget(portNumberTCP,1,2);
theLayout->addWidget(Browse1, 0, 1);
theLayout->addWidget(Browse2, 1, 1);
theLayout->addWidget(startUDP,0,3);
theLayout->addWidget(nic,0,4);
theLayout->addWidget(TCPfile,1,0);
theLayout->addWidget(UDPfile,0,0);
theLayout->addWidget(startTCP,1,3);
theLayout->addWidget(lblStatusUDP,2,0,1,3);
theLayout->addWidget(lblStatusTCP,3,0,1,3);
setLayout(theLayout);
connect(startUDP, SIGNAL(clicked()), this, SLOT(requestAnotherUDP()));
connect(startTCP, SIGNAL(clicked()), this, SLOT(requestAnotherTCP()));
connect(Browse1,SIGNAL(clicked()),this,SLOT(catchBrowse1()));
connect(Browse2,SIGNAL(clicked()),this,SLOT(catchBrowse2()));
connect(TCPSocket, SIGNAL(connected()) , this , SLOT(catchConnected()));
}
void MyClient::requestAnotherUDP()
{
actions++;
QFile file(UDPfile
->text
());
int sendData = qrand() % 10;
startUDP->setEnabled(false);
blockSize = 0;
UDPSocket->abort();
UDPSocket->connectToHost(nic->text(),portNumberUDP->text().toInt());
lblStatusUDP
->setText
("UDP: " + QString::number(actions
) + ". Sending file to "+nic
->text
()+" on port " + portNumberUDP
->text
());
while(!infile.atEnd())
{
infile >> block;
block.append(' ');
BigBlock.append(block);
}
in.writeBytes(BigBlock,BigBlock.length());
UDPSocket->disconnect();
UDPSocket->waitForDisconnected(3000);
lblStatusUDP
->setText
("UDP: " + QString::number(actions
) + ". Sent file to "+nic
->text
()+" on port " + portNumberUDP
->text
());
startUDP->setEnabled(true);
}
void MyClient::requestAnotherTCP()
{
actions++;
startTCP->setEnabled(false);
blockSize = 0;
TCPSocket->abort();
TCPSocket->connectToHost(nic->text(),portNumberTCP->text().toInt());
TCPSocket->setReadBufferSize(50000000);
}
void MyClient::catchConnected()
{
qDebug("Connected");
QFile file(TCPfile
->text
());
char point[1500];
if(TCPSocket->isValid())
{
lblStatusTCP
->setText
("TCP: " + QString::number(actions
) + ". Sending file to "+nic
->text
()+" on port " + portNumberTCP
->text
());
QFile newfile
("Test.dat");
int totalbytes = 0;
int totalbytes2 = 0;
int count = -1;
int count2 = -1;
while(!infile.atEnd())
{
count = infile.readRawData(point,1500);
count2 = in.writeRawData(point,count);
if(!TCPSocket->waitForBytesWritten(300))
{
}
totalbytes2 += fi.writeRawData(point,count);
if(count2 == -1)
{
}
}
TCPSocket->waitForBytesWritten(3000);
newfile.waitForBytesWritten(3000);
newfile.close();
startTCP->setEnabled(true);
TCPSocket->flush();
TCPSocket->disconnectFromHost();
TCPSocket->waitForDisconnected(-1);
lblStatusTCP
->setText
("TCP: " + QString::number(actions
) + ". Sent file to "+nic
->text
()+" on port " + portNumberTCP
->text
());
}
}
void MyClient::catchBrowse1()
{
if(!strfile.isEmpty())
{
UDPfile->setText(strfile);
}
}
void MyClient::catchBrowse2()
{
if(!strfile.isEmpty())
{
TCPfile->setText(strfile);
}
}