PDA

View Full Version : Simple chat example. How can I make a list of participants?



Luga
5th June 2009, 17:41
Hi everyone!
I need to make a chat. On your site I found an example (http://wiki.qtcentre.org/index.php?title=Simple_chat). But there's no list of participants. How can I do?

Do I understand that the data on a server need to send in that format?
And if the server receives GRTNG, it verifies the existence of party with the same name and save it.?


QByteArray arrBlock;
QDataStream out (& arrBlock, QIODevice:: WriteOnly);
out.setVersion (QDataStream:: Qt_4_5);
out <<quint16 (0) << QString("GRTNG") << nick->text ();
out.device () -> seek (0);
out <<quint16 (arrBlock.size () - sizeof (quint16));
socket-> write (arrBlock);

and


QByteArray arrBlock;
QDataStream out (& arrBlock, QIODevice:: WriteOnly);
out.setVersion (QDataStream:: Qt_4_5);
out <<quint16 (0) << QString("MSG") << message->text ();
out.device () -> seek (0);
out <<quint16 (arrBlock.size () - sizeof (quint16));
socket-> write (arrBlock);

I am sorry for my bad English. I hope you understand me. :o

kei
5th June 2009, 19:41
Have you seen this: Network Chat Example (http://doc.qtsoftware.com/4.5/network-network-chat.html)

Luga
5th June 2009, 19:51
Have you seen this: Network Chat Example (http://doc.qtsoftware.com/4.5/network-network-chat.html)

Yes, I have seen this example. This is not a client-server chat. And I did not understand the code. All very confusing. :(

tpf80
11th June 2009, 04:26
On the server you have:


QList<QTcpSocket*> connections;

so pretty much you just need to make an array of usernames which is indexed by the socket ID's in the list.

whenever the list changes because other users connected, you would need to make the server send the list to all of the clients because only the server is aware of all the client connections.