Re: sockets: connecting several UDP clients
- From: Josef Moellers <josef.moellers@xxxxxxxxxxxxxxxxxxx>
- Date: Thu, 22 Jan 2009 10:35:00 +0100
Gernot Frisch wrote:
I need a socket for send_to(), don't I?
Yes, but you can use *one* SOCK_DGRAM socket for all send_to()s, independent of the IP address, as that is specified in the send_to() calls!
A-ha!
So, basically My application has a list of TCP sockets for TCP communication, and _one_ UDP socket, globally for everything.
SCOKET udp_socket = socket(AF_INET, SOCK_DGRAM,IPPROTO_UDP);
// no bind(), no nothing here
// And then I can write functions like:
UDP_sendTo(udp_socket, ulong IP, ushort port, char* message);
UDP_getFrom(udp_socket, ushort port, char* message);
Where the IP + port should be stored in a sockaddr_in for convenience.
Is that correct?
Basically: yes, apart from David's remark about bind()ing the SOCK_DGRAM port.
I think I finally understood what they all talked about "UDP is connectionless". It's just IP+port and _one_ global udp socket for the protocol.
Note that, apart from being "connectionless", UDP is also "unreliable", i.e. you cannot guarantee that a packet you send will actually reach its destination.
Josef
--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html
.
- References:
- sockets: connecting several UDP clients
- From: Gernot Frisch
- Re: sockets: connecting several UDP clients
- From: Josef Moellers
- Re: sockets: connecting several UDP clients
- From: Gernot Frisch
- Re: sockets: connecting several UDP clients
- From: Josef Moellers
- Re: sockets: connecting several UDP clients
- From: Gernot Frisch
- Re: sockets: connecting several UDP clients
- From: Josef Moellers
- Re: sockets: connecting several UDP clients
- From: Gernot Frisch
- Re: sockets: connecting several UDP clients
- From: Josef Moellers
- Re: sockets: connecting several UDP clients
- From: Gernot Frisch
- Re: sockets: connecting several UDP clients
- From: Josef Moellers
- Re: sockets: connecting several UDP clients
- From: Gernot Frisch
- sockets: connecting several UDP clients
- Prev by Date: Re: sockets: connecting several UDP clients
- Next by Date: Re: sockets: connecting several UDP clients
- Previous by thread: Re: sockets: connecting several UDP clients
- Next by thread: c++ library functions
- Index(es):
Relevant Pages
|