sockets - C Handling multiple types of UDP packets -


i'm writing application listens incoming udp packets. there's possibility of receiving many different types of packets. instance, packets defined such,

package a: | int | char b | int c |

package b: | short int d | int e | char f |

and forth.

my question is, given i'm receiving multiple types of messages, what's method coordinating what's being sent i'm reading?

as see it, "header" added beginning of each message, defining type or read message length , compare have listed, if know size of each packet.

also, if later option, packet guaranteed expected length each time?

edit:

i can see using packet length problem there multiple messages types of same length.

use header contains magic word , code defines type. way can assure intended application, , identifies correct parser use.

a sequence number , timestamp useful detect lost packets , arriving out of sequence. these common issues encountered udp.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -