Network Programming Error/Line Edit
Dear All,
I have created a Application using Qt Network Class. I have created a SERVER and CLIENT. Here Client is sending the data to Server. In server after accepting the New connection, Server socket reads the Packet data from Client. After analysing it. It should send the data to another Page(Mulitple MainWindows) on the same Application of the Server. Here I'm able to see all Debug messages. In server after logging in, It takes to child window is there. Here Lineedit are declared. Here the Data should Appear after checking the start bit after ReadLine in the child Window.
SERVER Code:
Code:
{
hAddr.setAddress("192.168.64.55");
//server->listen(hAddr,1234);
Client Side:
qDebug("Listening to new connection");
}
void TeamStatus::on_newconn()
{
socket=server->nextPendingConnection();
{
qDebug("new connection1 established");
}
connect(socket,SIGNAL(readyRead()),this,SLOT(read_socket()));
}
void TeamStatus::read_socket()
{
if(buffer.startsWith("1"))
{
qDebug()<<buffer;
qDebug("Next Page");
qDebug()<<buf;
tempage.le1->setText(buf); //This the another page where Line Edit is declared as le1... TEAMPAGE is made object at TEAMSTATUS.H file as teampage
}
if(buffer.startsWith("2"))
{
qDebug()<<buffer;
qDebug("Next Page");
qDebug()<<buf;
tempage.le2->setText(buf); //This the another page where Line Edit is declared as le1... TEAMPAGE is made object at TEAMSTATUS.H file as teampage
}
CLIENT CODE
Code:
void TCPClient::write()
QString Data
="",Data1
=this
->le
->text
();
CHAT="1";
Data.append(CHAT);
Data.append(Data1);
socket->write(Data.toUtf8().constData());
qDebug("Client Sent 1 to Server");
socket->flush();
}
void TCPClient::write1()
{
QString Data
="",Data1
=this
->le
->text
();
CHAT="2";
Data.append(CHAT);
Data.append(Data1);
socket->write(Data.toUtf8().constData());
qDebug("Client Sent 2 to server");
socket->flush();
}
Please Help I'm Stuck up here :) I'm not getting the text at the Server Lineedits. In debug msgs in console we can see, but not on the Application Window.
Re: Network Programming Error/Line Edit
Check that you are actually seeing those two line edits, not two other line edits
E.g. set some text before you start to listen. Do you see the text when no client is connected.
Cheers,
_
Re: Network Programming Error/Line Edit
You are assuming that readyRead() will be called once for each complete 'line' from the sender. This will rarely be the case. You cannot assume the first character in a read is the first character of a line, that the last character is the end of a line, or that you have only parts of a single line.
You must buffer what is received until you can find a complete line in the data and then process it. You must leave any unprocessed data in the buffer.
It it also not clear that you are sending a line ending, e.g. CR and/or LF, that the receiver will be looking for when reading a line.
Re: Network Programming Error/Line Edit
Ya.. I made listen() function Disable in the same page and set the TEXT as tempage.setText->("NAME"). After compilation, I saw the Text in the child window in the required/assigned place. After getting connected to server, or while sending or receiving from client. The data packet is not getting checked and pushing the data in the required Line edits.Any problem can be in the Server packets or its connection.