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 8587461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:34:29+00:00 2026-06-11T22:34:29+00:00

I am working on a LAN based solution with a server that has to

  • 0

I am working on a LAN based solution with a “server” that has to control a number of “players”
My protocol of choice is UDP because its easy, I do not need connections, my traffic consists only of short commands from time to time and I want to use a mix of broadcast messages for syncing and single target messages for player individual commands.

Multicast TCP would be an alternative, but its more complicated, not exactly suited for the task and often not well supported by hardware.

Unfortunately I am running into a strange problem:

The first datagram which is sent to a specific ip using “sendto” is lost.
Any datagram sent short time afterwards to the same ip is received.
But if i wait some time (a few minutes) the first “sendto” is lost again.

Broadcast datagrams always work.
Local sends (to the same computer) always work.

I presume the operating system or the router/switch has some translation table from IP to MAC addresses which gets forgotten when not being used for some minutes and that unfortunately causes datagrams to be lost.
I could observe that behaviour with different router/switch hardware, so my suspect is the windows networking layer.

I know that UDP is by definition “unreliable” but I cannot believe that this goes so far that even if the physical connection is working and everything is well defined packets can get lost. Then it would be literally worthless.

Technically I am opening an UDP Socket,
bind it to a port and INADRR_ANY.
Then I am using “sendto” and “recvfrom”.
I never do a connect – I dont want to because I have several players. As far as I know UDP should work without connect.

My current workaround is that I regularly send dummy datagrams to all specific player ips – that solves the problem but its somehow “unsatisfying”

Question: Does anybody know that problem? Where does it come from? How can I solve it?

Edit:

I boiled it down to the following test program:

int _tmain(int argc, _TCHAR* argv[])
{
    WSADATA wsaData;
    WSAStartup(MAKEWORD(2, 2), &wsaData);
    SOCKET Sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
    SOCKADDR_IN Local = {0};
    Local.sin_family = AF_INET;
    Local.sin_addr.S_un.S_addr = htonl(INADDR_ANY);
    Local.sin_port = htons(1234);
    bind(Sock, (SOCKADDR*)&Local, sizeof(Local));
    printf("Press any key to send...\n");
    int Ret, i = 0;
    char Buf[4096];

    SOCKADDR_IN Remote = {0};
    Remote.sin_family = AF_INET;
    Remote.sin_addr.S_un.S_addr = inet_addr("192.168.1.12");  // Replace this with a valid LAN IP which is not the hosts one
    Remote.sin_port = htons(1235);

    while(true) {
        _getch();
        sprintf(Buf, "ping %d", ++i);
        printf("Multiple sending \"%s\"\n", Buf);

        // Ret = connect(Sock, (SOCKADDR*)&Remote, sizeof(Remote));
        // if (Ret == SOCKET_ERROR) printf("Connect Error!\n", Buf);
        Ret = sendto(Sock, Buf, strlen(Buf), 0, (SOCKADDR*)&Remote, sizeof(Remote));
        if (Ret != strlen(Buf)) printf("Send Error!\n", Buf);
        Ret = sendto(Sock, Buf, strlen(Buf), 0, (SOCKADDR*)&Remote, sizeof(Remote));
        if (Ret != strlen(Buf)) printf("Send Error!\n", Buf);
        Ret = sendto(Sock, Buf, strlen(Buf), 0, (SOCKADDR*)&Remote, sizeof(Remote));
        if (Ret != strlen(Buf)) printf("Send Error!\n", Buf);
        }
    return 0;

The Program opens an UDP Socket, and sends 3 datagrams in a row on every keystroke to a specific IP.
Run that whith wireshark observing your UDP traffic, press a key, wait a while and press a key again.
You do not need a receiver on the remote IP, makes no difference, except you wont get the black marked “not reachable” packets.
This is what you get:

Wireshark Snapshot

As you can see the first sending initiated a ARP search for the IP. While that search was pending the first 2 of the 3 successive sends were lost.
The second keystroke (after the IP search was complete) properly sent 3 messages.
You may now repeat sending messages and it will work until you wait (about a minute until the adress translation gets lost again) then you will see dropouts again.

That means: There is no send buffer when sending UDP messages and there are ARP requests pending! All messages get lost except the last one.
Also “sendto” does not block until it successfully delivered, and there is no error return!

Well, that surprises me and makes me a little bit sad, because it means that I have to live with my current workaround or implement an ACK system that only sends one message at a time and then waits for reply – which would not be easy any more and imply many difficulties.

  • 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-06-11T22:34:31+00:00Added an answer on June 11, 2026 at 10:34 pm

    I’m posting this long after it’s been answered by others, but it’s directly related.

    Winsock drops UDP packets if there’s no ARP entry for the destination address (or the gateway for the destination).

    Thus it’s quite likely some of the first UDP packet gets dropped as at that time there’s no ARP entry – and unlike most other operating systems, winsock only queues 1 packet while the the ARP request completes.

    This is documented here:

    ARP queues only one outbound IP datagram for a specified destination
    address while that IP address is being resolved to a MAC address. If a
    UDP-based application sends multiple IP datagrams to a single
    destination address without any pauses between them, some of the
    datagrams may be dropped if there is no ARP cache entry already
    present. An application can compensate for this by calling the
    Iphlpapi.dll routine SendArp() to establish an ARP cache entry, before
    sending the stream of packets.

    The same behavior can be observed on Mac OS X and FreeBSD:

    When an interface requests a mapping for an address not
    in the cache, ARP queues the message which requires the
    mapping and broadcasts a message on the associated associated
    network requesting the address mapping. If a response is
    provided, the new mapping is cached and any pending message is
    transmitted. ARP will queue at most one packet while waiting
    for a response to a mapping request; only the most recently
    “transmitted” packet is kept.

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

Sidebar

Related Questions

I am currently working on server application that has to deal with reasonable amount
I am working on a computer that is joined with server in LAN.proxy is
I am working on a Mac that has an Ethernet connection to a LAN
I am working on Lan based interoffice messaging system. The steps in my applications
Working with an undisclosed API, I found a function that can set the number
I'm working on a Wake on LAN service that will run from a web
I'm working on a web app that works fine inside the LAN using HTTP
I'm working on setting up version control on a company LAN using the setup
Now in my program in c# that simulates the working of a lan-messenger I
I'm working on a C# application that queries a SQL Server 2008 Express instance

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.