How to make perfect client-server communication program using iPhone and C# -


I have created an iPhone app that captures the voice and uses the NSOutputStream example Is streamed on the server. After the stream is closed, the iPhone sends a text message on the server as "--- end ---" and starts indexing on NSOutputStream . When the server has captured the message "--- end ---", it does some processing and writes the text back to the customer. Closing the NSOutputStream and NSInputStream connection after receiving the last message to the client.

Every time, before sending the "end" message I put the application to sleep for 0.5 seconds. Then I can guarantee that the final message is not mixed with other data. It works well with the system simulator and in my network (100 Mbps).

However, when I added the entire application to slow down the network (1.2 Mbps), then the entire communication disappeared. Sometimes the end message is mixing with voice data as soon as the last message is added to the text from the server. But when I change the thread sleeping time for 3 seconds in the server and the client, the error context rate decreases.

I know that this may be an issue of the design of my network client-server communication protocol. But I do not know how to fix this right.

Can anyone explain to me, how can I overcome these issues?

Instead of adding an arbitrary sleep time, learn how to wait for a transfer.


Comments