Thread: UDP programming

  1. #1
    Registered User Mortissus's Avatar
    Join Date
    Dec 2004
    Location
    Brazil, Porto Alegre
    Posts
    152

    UDP programming

    Hi! I have some doubts about UDP programming. Iīve been trying to find answers, but couldīt find . Any link or response is much appreciated!

    1) Can I send and receive using the same socket in multithread? Must I use semaphores?

    2) If two hosts send something at the same time, both the datagrams will be sent, or they will be dropped? I know that UDP is a little unreliable, but can this kind of error occur, or Ethernet protocol deals with it?

    Again, thanks any help.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Quote Originally Posted by Mortissus

    2) If two hosts send something at the same time, both the datagrams will be sent, or they will be dropped? I know that UDP is a little unreliable, but can this kind of error occur, or Ethernet protocol deals with it?
    Do you mean 2 hosts each sending a datagram to each other? In that case both would be receiveve each others datagram.

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    95
    To the first question:

    You don't need external synchronization just to send() and recv() in multiple threads on the same socket, but you'll likely sync. some at some point.

  4. #4
    Registered User Mortissus's Avatar
    Join Date
    Dec 2004
    Location
    Brazil, Porto Alegre
    Posts
    152
    Thanks for the answer!

    I will try to better explain the second question. Is UDP safe against collision (physical level)? I need to know what kind of errors can I have with UDP, that I do not have with TCP, besides datagrams dropped and arriving out of order. What I must consider when programming UDP, that I do not need to worry with TCP.

    As always, thanks any kind of help.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Other then datagrams ariving out of order and being dropped they can be corupted or duplicated.
    If both hosts send a datagram they wont collide, the router(s) will still foreward both allthoug neither is guaranteed to arive and each host may not receive the others datagram at EXACLY the same time.

  6. #6
    Registered User Mortissus's Avatar
    Join Date
    Dec 2004
    Location
    Brazil, Porto Alegre
    Posts
    152
    Ok! Thanks very much!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with UDP
    By AlexS in forum C# Programming
    Replies: 0
    Last Post: 07-07-2009, 06:21 PM
  2. simultaneously waiting for data on FIFO and UDP using select call
    By yogesh3073 in forum Networking/Device Communication
    Replies: 2
    Last Post: 01-05-2007, 09:53 AM
  3. C++ Builder UDP programming
    By Hankyaku in forum Networking/Device Communication
    Replies: 5
    Last Post: 09-17-2005, 08:41 AM
  4. Traceroute using UDP and ICMP
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 08-09-2002, 07:09 PM
  5. Traceroute using UDP + ICMP
    By Unregistered in forum Windows Programming
    Replies: 0
    Last Post: 08-05-2002, 10:50 AM