PDA

View Full Version : Network Communication Architecture



mhoover
29th May 2009, 01:24
I want to architect a client and a server where the server sends out data periodically and is able to receive commands. Since the clients need to be able to send commands and receive data, both the client and the server have to have the ability to read and write.

I'm trying to find a good template to get started. It looks like the fortuneclient/fortune server example won't work because the server is not able to read anything from the client. It only detects new connections. Is that right?

I suppose I could use QUdpSocket on both the client and the server and just use the readDatagram/writeDatagram functions to implement reading and writing. If I go down this path, would I need to use different ports for the commands to the server and the responses from the server? Also, is there an example that uses this?

Sorry for asking such a broad question on this. Thanks in advance for whatever help may come.

^NyAw^
29th May 2009, 10:20
Hi,



I'm trying to find a good template to get started. It looks like the fortuneclient/fortune server example won't work because the server is not able to read anything from the client. It only detects new connections. Is that right?


The server is able to recive data. Just connect "readyRead" signal to any slot. The server is the one who accepts the connection but then the communication can be done by the two ways.



I suppose I could use QUdpSocket on both the client and the server and just use the readDatagram/writeDatagram functions to implement reading and writing. If I go down this path, would I need to use different ports for the commands to the server and the responses from the server? Also, is there an example that uses this?


You can use QUdpSocket if you want UDP datagrams or QTcpSocket if you want to use TCP streams.
Using UDP may become on loosing data, but imagine that you try to develop a Voice IP application that the sound have to arrive as it is sent. Then you have to play all the sound that is arriving and can't wait if there are data lost.
On the other hand, imaginge that you send images that have to be stored. Then you need TCP because TCP implements a resending mechanism if there is data lost.

Hope it helps.

mhoover
30th May 2009, 04:49
Very helpful response. Thank you!

I ended up using the QUdpSocket and it works great!

Like the pikachu signature.