Sending a huge amount of real time processed data via UDP to iPhone from a server

前端 未结 2 506
臣服心动
臣服心动 2021-02-04 19:15

I\'m implementing a remote application. The server will process & render data in real time as animation. (a series of images, to be precise) Each time, an image is rendered,

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-04 19:48

    Assuming that you have a very specific and good reason for using UDP and that you need all your data to arrive ( i.e. you can't tolerate any lost data ) then there are a few things you need to do ( this assumes a uni-cast application ):

    1. Add a sequence number to the header for each packet
    2. Ack each packet
    3. Set up a retransmit timer which resends the packet if no ack recv'ed
    4. Track latency RTT ( round trip time ) so you know how long to set your timers for
    5. Potentially deal with out of order data arrival if that's important to your app
    6. Increase receive buffer size on client socket.

    Also, you could be sending so fast that you are dropping packets internally on the sending machine without them even getting out the NIC onto the wire. On certain systems calling select for write-ablity on the sending socket can help with this. Also, calling connect on the UDP socket can speed up performance leading to less dropped packets.

    Basically, if you need guaranteed in-order delivery of your data than you are going to re-implement TCP on top of UDP. If the only reason you use UDP is latency, then you can probably use TCP and disable the Nagle Algorithm. If you want packetized data with reliable low latency delivery another possibility is SCTP, also with Nagle disabled. It can also provide out-of-order delivery to speed things up even more.

    I would recommend Steven's "Unix Network Programming" which has a section on advanced UDP and when it's appropriate to use UDP instead of TCP. As a note, he recommends against using UDP for bulk data transfer, although the reality is that this is becoming much more common these days for streaming multimedia apps.

提交回复
热议问题