c - Configuring multiple UDP sockets on a single port -
i'm trying implement peer-to-peer chat application using udp , wondering how scale program multiple users.
as understand it, udp needs 1 socket send , receive data using recvfrom
, sendto
functions. using data address fields passed these functions, can determine user i'm communicating with.
i wondering if create multiple udp sockets on same port each peer i'm talking to. way, if data comes peer x, data goes udp port , gets passed appropriate socket 'bound' x's address.
is there anyway while still using udp?
yes, can specify so_reuseaddr (so_reuseport on linux) before binding udp socket (all sockets including first), , connect each socket appropriate target, it's not necessary. dispatch each message arriving on single socket according source-address.
Comments
Post a Comment