Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6214089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:48:51+00:00 2026-05-24T06:48:51+00:00

I need a UDP server that can communicate with many clients. My current thinking

  • 0

I need a UDP server that can communicate with many clients.

My current thinking is

  1. open a socket
  2. bind to a port
  3. recvfrom the client
  4. fork
    • child: process the message, open a new socket and sendto the client
    • parent: go to step 3

The server replies to the client on the same port from which the client connected, but from a random port.

I’ve implemented this, and with my test client, it works.

However, the real client is being written by someone else, somewhere else. (It’s an embedded system)

His client is expecting a reply from the same port to which he sent the message. The only way I can seem to do this is by using the same socket, which does work.

My worry though, is that will cause problems if more than one client tries to connect at once.

How should this be done?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:48:52+00:00Added an answer on May 24, 2026 at 6:48 am

    UDP sockets are much simpler then TCP ones. Just reply on the same socket with sendto(2) with client address you got from recvfrom(2). No need to mess this threads, just do it in a loop.

    Edit 0:

    To elaborate a bit after your comment – when you get a datagram on a UDP socket you don’t get a new socket descriptor like with TCP, so your parent still handles all the input. Now, do you plan on fork(2)-ing a new process and then creating a new socket for every packet? Or do you want to keep track of source addresses and map them to child processes and setup some sort of message passing from parent to child? I wouldn’t do either. The overhead is just too great. Just do it inline.

    Then if your message rates are really high and your processing is really heavy – increase server socket receive buffer (SO_RCVBUF, setsockopt(2)), look into threading your server splitting it into I/O and processing parts, look into lock-free queuing, etc. But that last part is a whole different story. Start simple.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need an app that sends an UDP packet to some network server and
I'm writing a UDP multicast client/server pair in C# and I need a delay
While testing out a UDP multicast server that I've written on Windows 7 Ultimate
I'm trying to build a server that will handle many concurrent connections to iPhone
I need to write an UDP server which will wait for packets from uncorrelated
In which situration should we use an async socket (either Tcp or Udp) server
I need to create server and client programs with synapse using UDP protocol. I
I'm currently working on a UDP socket application and I need to build in
I'm implementing a network server that processes udp packets. I want to avoid replay
I need to get the source IP for a datagram in a UDP server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.