[Qt-interest] QTcpSocket missing some data
Srikanth Bemineni
srikanth.bemineni at gmail.com
Sat Feb 7 01:04:00 CET 2009
Hi
I have server and a client program .The client uses QTcpsocket to send the
data and I Cserver to accept the connections.I have made it event based to
whenever I receive the data from the client. When I write two messages in
this case these are commands.I only receive only one. When I put in debug I
get both the messages.
/*******************************************************************************************/
writeToServer( "i ready");
writeToServer( "i get");
#################################################################
writeToServer(QString szTempMsg )
{
szTempMsg = outputMsg;
if( szTempMsg.at( szTempMsg.length() - 1 ) != '\n' )
szTempMsg += "\n";
// Also check that the socket has a connection
if (CallerSocket->state() == QTcpSocket::ConnectedState) {
if (CallerSocket->write(szTempMsg.toAscii(), szTempMsg.length()) ==
-1) {
cout<<"Error writing"
}
CallerSocket->flush();
}
}
/******************************************************************************************/
Server
##################################################################
connect( clientSocket, SIGNAL( readyRead() ), this,
SLOT( slot_ClientSocketInputArrived() ) );
void CBaseManager::slot_ClientSocketInputArrived()
{
QTextStream ts( clientSocket );
QString szClientData = "";
HDUTRACE1( "CBaseManager::ClientSocketInputArrived()" );
while( clientSocket->canReadLine() )
{
szClientData = ts.readLine();
// Check if there is a new line or double new line character on the
input
if( szClientData.endsWith( "\n" ) )
szClientData = szClientData.left( szClientData.length() - 1 );
else if( szClientData.endsWith( "\n\n" ) )
szClientData = szClientData.left( szClientData.length() - 2 );
// emit the signal that data from the client has arrived
if( szClientData != "" )
{
TRACE1( "Emitting clientDataReady signal." );
emit clientDataReady( szClientData );
}
}
}
######################################################################
--
_/\_
With Regards
SB Angel Warrior
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090206/4b5b9375/attachment.html
More information about the Qt-interest-old
mailing list