Thank you for the fast reply
However, i believe i should work in a different way. I mean, this is the code of my server, (which is also very similar to the client). The readyread() function manages the message sent between the two users. Shouldn't i edit that function?
Consider that i know the code to send and receive the file (which i can even post you later) but i dunno how to "filter" the two different things.
#include "myserver.h"
#include "std_lib_facilities.h"
MyServer::MyServer(QObject *parent) :
QObject(parent)
{
//initial server
server = new QTcpServer();
//connect signal and slots
//if a new connection is triggered.
//The server will execute slot newConnection();
connect(server,SIGNAL(newConnection()),this,SLOT(n ewConnection()));
}
void MyServer::startServer(){
//server starts listen port
server->listen(QHostAddress::Any,port);
}
void MyServer::setPort(int port)
{
this->port=port;
}
void MyServer::stopServer(){
//close server
server->close();
}
void MyServer::newConnection(){
//assign socket to new connection
socket = server->nextPendingConnection();
//connect signal and slots, if the client send a message the readyRead();
//will trigger slot readyRead().
connect(socket,SIGNAL(readyRead()),this,SLOT(ready Read()));
}
void MyServer::readyRead(){
while(socket->canReadLine()){
//socket read a line with a UTF8 format
QString line = QString::fromUtf8(socket->readLine());
//socket return the line that socket just read.
socket->write(line.toAscii());
//signal ui to update
emit updateUI(line);
}
}
void MyServer::sendText(QString text){
QString output="server [";
output.append(QString::fromStdString(this->ltime.timeSystem()));
output.append("]:");
text = text + "\r\n";
output.append(text);
socket->write(output.toAscii());
emit updateUI(output);
}
Bookmarks