PDA

View Full Version : TCP Protocol Implementation



keelerjr12
24th August 2012, 18:37
So I need to send data between a server and client over TCP inside a vehicle. Currently, I have the server up and running but just need to figure out the actual implementation of the data transfer. For the client I need to do the same and figure out how to render the QML correctly. Anyway, what would be a good way to pass data containing QML models or even data such as Artist, Song, and Album (think iPod menu) and then also pass data regarding the song currently playing (song updates like time playing, etc.).

Any ideas about a good way of implementing a protocol to handle this? Basically the center stack is the server and handles the logic while the cluster/client is just a view that renders QML. I was thinking about just passing QStringLists with model information and then dynamically swapping models within the view. Also, I need to send images over TCP while the song is playing for things like Album art.

Also, I need an effective way to cache these images and probably the models too, so the client doesn't need to make a request to the server on every menu switch. Again, think about how an iPod works and that's what I'm going for.

tbscope
26th August 2012, 13:22
Why did you choose for a server and client based solution? Are you planning for multiple clients?

I would run a sql database on the server and let the client(s) be the graphical interface.
You can copy and store the images on the client side, but if the network connection is sufficiently fast (10 or 100 Mb/s), that wouldn't make a lot of difference, especially if the images are small. I guess these would load fast enough over the network. Did you test this? Did you have negative experiences with this?

keelerjr12
26th August 2012, 16:55
The reason I decided to go with a client-server application was because the client represents the dashboard HMI in the vehicle and the server would be the center console. I also had never really thought about just using a SQLite database on the center stack, however. I'm not sure this would satisfy my requirements though. The dashboard HMI (screen next to speedometer and gauges) needs to have as little logic as possible. The reason for this is so it doesn't have to be flashed constantly (basically changing the server portion changes the client). So that's why I kinda' went with just passing model data around. And this is very fast because it's all done through ethernet. At first I thought about HTTP but I'd still have to implement the server using TCP so I might as well just do the whole architecture in pure TCP.

I have most of it implemented; now I just need to come up with a message passing scheme. Also, I am looking at having multiple clients. So you can control the in-vehicle systems from the driver seat or someone in the back on an iPad can change the radio, etc; but this isn't necessarily a requirement.

tbscope
26th August 2012, 20:34
Have a look at QXmlStreamReader and Writer.
Assuming you don't need a lot of security, you basically set up a simple server and client, then use the stream reader and writer to pass data to each other.
That way you don't have to reinvent anything.

Edit 1: However this will not work well for image data. You will need to encode/decode the image data (base64, ...)
Edit 2: If you use Linux, you can also use DBus.

keelerjr12
27th August 2012, 03:22
I will need to send image data for album art but I will check into encoding it. Also, is this an efficient way of sending updates every second when the QTimer event fires?