07-20-2010 01:18 PM - edited 07-20-2010 01:19 PM
Greetings,
I'm trying to send a waveform across TCP/IP from a server to a client. The waveform is a display of input from a microphone or sound card. It works, but not very well. It's quite slow. The graph updates every 1-2 seconds. I'm trying to obtain a fluid animation. Does anyone have any suggestions on how I could speed up this transfer? I'm including screenshots from the block diagram of both the server and the client.
It could also be that it's just not transferring consistently fast enough. When the graph does update it quickly shows some movement (what looks like a few updates) at once for a fraction of a second.
I suspect this is related to the problem of it being too slow, but if I let it run for a little while I begin to get errors from the sound read VI on the server (probably because the buffer has overflown).
Thanks for any advice,
Pheria
07-20-2010 05:45 PM
Are the two computers on the same subnet, or is this over the internet?
In the client code you have a hard-wired value for the number of bytes, with a "wait forever" timeout. Are you sure you're getting that number of bytes at once? If you look at the TCP/IP examples that ship with LabVIEW you'll notice that prior to sending the actual data, the expected number of bytes is sent, so the client will know how much data to expect.
If the value is right, you may not be getting all the data at once. For instance, you may only get 2000 bytes, and then the TCP Read needs to wait for the rest. You may want to consider performing "tight" reads. I.e., a read with a very short timeout that grabs whatever is available. My suggestion is to play around with the TCP/IP example VIs (such as the Simple Data Client and Simple Data Server).
07-21-2010 09:03 AM
Ah, yes. I probably should have mentioned that. The sound is sampled 600 samples at a time, and those 600 are sent over TCP/IP. Since it's always 600, the byte size is always the same. Both computers are/will be on the same subnet. In fact, to start I'm just testing them on the same machine using localhost.
I think I've tried something similar to what you're talking about. I try telling TCP Read to read in immediate mode, and to timeout at 150ms. In immediate mode," Waits until the function receives any bytes from those you specify in bytes to read. Waits the full timeout only if the function receives no bytes. Returns the number of bytes so far. Reports a timeout error if the function receives no bytes."
When I try it this way, I get a timeout error.
I need my program do perform at a rate of 150ms or better, so I guess the server program is sending data too slowly. I'm not sure how to send it more fluidly, though. If I cut down the number of samples by much, there isn't enough information to fill all divisions on the client's waveform graph. I suppose I could use shift registers in the client and combine short waveform pieces, but even if I send half as much information that means it would have to send it twice as fast to meet the update requirement.
I'll look at these examples again. Thanks for giving some advice, smercurio_fc.
If anyone else has any suggestions, I'd be grateful for them.
07-21-2010 09:33 AM
Pheria wrote:When I try it this way, I get a timeout error.
Of course you will - that's expected, but since you know the reason for the timeout you can ignore it.