Do you mean that you have one socket sending data to several clients from the server side? And you want to call write() to send data for all clients by THAT SAME socket ?Quote:
Originally Posted by Vivek1982
Printable View
Do you mean that you have one socket sending data to several clients from the server side? And you want to call write() to send data for all clients by THAT SAME socket ?Quote:
Originally Posted by Vivek1982
Not exactly at the same time, two or more clients will send data to server. Server will analyse and process the data send by all the clients. Later Server will send data to all connected clients. After receiving the data from server, All the clients update the info/data sent by the server in all Client Application.
After searching in this Qt Forum, I made attempt to write data on server by using below mentioned code, but it was not working.
Code:
void Server::writetoallclients() { foreach(QtcpSocket *socket,socket) { socket->write(Data.toUtf8().constData()); qDebug("data sent to all Clients"); } }
Code:
void Client::read() { qDebug("start reading the socket"); qDebug("data rxcd from server ");
Dear all.. Waiting for reply...application is at final stage..I can compete soon
If you want to send to all clients, you need to keep all incoming sockets, e.g. in a list, and when sending you iterate over that container and call write on all sockets.
Cheers,
_
Thanks for the reply.... I will give my attempt. . Any alternate idea to get this done by seeing my earlier posts is most welcome to all
I dont think there is any other idea to do that because to send to one client you have to send the data from server through the connected socket. Hence to send data to all clients you have to send the data through all connected sockets. Iterating over the sockets is a good idea as posted above by anda_skoa.
You can give it an attempt save all sockets in a container of some type and add sockets to it through nextPendingConnection since it will return the connected socket and then make a method for example sendToAll() where you iterate over the items and send the message one by one.
Good Luck.
Ok... I hope this may work by QList<>.
In my new connection slot I need to try like
QList<QTcpsocket*,sockets>=new QTcpsocket.
But after declaring as aQList.we have to set socket descriptor or not required? Then we can try to sendtoall().
Okay now this may work for data to all the clients.... As mentioned above post if I need to send data for specific client.not suddenly at the same time to respective client who has sent data to server...later also...how this process will happen?
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
Code:
void Server::on_newconn() { 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"); }
Well, alternatively to iterating over a container one could make a client handler object for each socket that has a slot for sending and have the chat text source emit a matching signal when text should be sent.
Basically this is the same as iterating, just done internally by the signal/slot system.
Cheers,
_
I have got output where many clients can be connected to one server, two way data can be sent means from server its multi cast to all connected clients...but in client now data is coming twice in line edits.how it can be solved
In post 29...in write() its data not CHAT
How many connected clients do you have?
Did you check how many times is the for loop iterating?
No...wat ever is the clients no, but out put is coming twice in lineedit s...I checked based on no of client connected.if no of clients is one or two or four...still text wat I send in server line edit...its appearing twice in Clint application
Check what's in the QByteArray buffer at the client side, is the message also saved twice there ?
Ya.. I checked fully,,, in my server side data of linedit is sent only once across all the clients, but where as in the client side QByteArray buffer, data is coming twice.
E.G: Server: lineedit=HI
Client:textedit=HIHI
Code:
void TCPClient::read1() { qDebug()<<buffer; te->setText(buffer); }
Code:
void Sever::on_pushButton_clicked() { qDebug()<<data; { socket->write(data.toUtf8().constData()); qDebug()<<data; } qDebug()<<data; qDebug("server is sending msgs to clients"); }
Any problem in my coding.....I'm checking for solutions all the time but no reply...why my client application receiving twice
Attach the whole project as a zip in order to investigate the problem.
Hi.. I have attached the complete project, how to address?.. data saving twice problem is resolved some how. plz go through the attachment. Plz correct me if i have gone wrong me in coding. Initially I request to read Application Text file once, before compiling code to understand the Project.
Well, there are a couple of bugs but the network stuff seems to work for me.
Any string sent by the server is only received once by each client.
Couple of bugs:
* SLOT((on_conn())) has one pair of () to much, should be SLOT(on_conn())
* you are creating invisible widgets and then throw away their pointers. waste of resources
* send buttons in client main window are connected cross-wise, i.e. the left button sends the right line edits contents
Cheers,
_
Plz can I get solution fixed for this... Or atleast line level solution where I need to work to get solution....I'm getting more confused with couple of bugs...please