As suggested I have used QList<> in server application to address all or send data to all clients. Now, all clients are able to send/read data.but, all clients all getting data twice.Any problem in my write function of Server
void Server::on_newconn()
{
QTcpSocket *socket
= server
->nextPendingConnection
();
sockets.append(socket);
connect(socket,SIGNAL(readyRead()),this,SLOT(read_socket()));
}
void Server::write()
{
{
socket->write(CHAT.toUtf8().constData());
}
qDebug("server is sending msgs to all clients");
}
void Server::on_newconn()
{
QTcpSocket *socket = server->nextPendingConnection();
if((socket->state()==QTcpSocket::ConnectedState))
sockets.append(socket);
connect(socket,SIGNAL(readyRead()),this,SLOT(read_socket()));
}
void Server::write()
{
QString data=this->le->text();
foreach(QTcpSocket* socket,sockets)
{
socket->write(CHAT.toUtf8().constData());
}
qDebug("server is sending msgs to all clients");
}
To copy to clipboard, switch view to plain text mode
void TCPClient::read1()
{
te->setText(buffer);
}
void TCPClient::read1()
{
QByteArray buffer= socket->readLine();
te->setText(buffer);
}
To copy to clipboard, switch view to plain text mode
Bookmarks