Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. UDP client implementation

UDP client implementation

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NewHSKid
    wrote on last edited by
    #1

    Hi, Can someone tell me how to implement a UDP client. I already did a TCP client (it works fine), and read some of the MSDN on some differences. Is the only difference that I use SOCK_DGRAM instead of SOCK_STREAM ? Where can I find a list of the protocols address family (af) for the function socket? Can some tell me where to find a detailed article or some sample code. Thanks. Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)

    G 1 Reply Last reply
    0
    • N NewHSKid

      Hi, Can someone tell me how to implement a UDP client. I already did a TCP client (it works fine), and read some of the MSDN on some differences. Is the only difference that I use SOCK_DGRAM instead of SOCK_STREAM ? Where can I find a list of the protocols address family (af) for the function socket? Can some tell me where to find a detailed article or some sample code. Thanks. Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)

      G Offline
      G Offline
      geo_m
      wrote on last edited by
      #2

      Well, during the creation you just pass the SOCKET_DGRAM instead of SOCKET_STREAM. Then you might 'bind' it to the local port (selecting the client side port number - unusual in tcp). If you don't do it it will choose the port automatically as in tcp, but most udp protocol expects also known client port, so usually you have to do it. Then the usage is slightly different - on write side whatever you write it will send a packet immediatelly (no nagle alg. as in tcp) therefore if you write every byte separately, there will be separate packet for every byte (thus big overhead). You also have to specify the destination address - this is in tcp taken from the 'connect', but there's no connect, because it's connectionless socket ;). Reading part - here you can use the recvfrom or WSARecvFrom functions which returns also the address from where the datagram was sent and you can process it. That's the difference between udp and tcp - in udp you can communicate with several computers using one socket. Therefore you have to specify the address in write and receive it in read. Another issue with udp is that it's not reliable - it's only best effort service, so during design of the protocol you have to think about the fact, that the packets (data) can be lost - this is normally controlled by tcp and in that case the data are resend, but it's not valid in udp, here it's up to you. That's just brief description of udp-tcp differences. I hope it's not too much confusing ;-)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups