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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:14:26+00:00 2026-05-23T11:14:26+00:00

I’ve been stuck at this issue for the last 4 days and I can’t

  • 0

I’ve been stuck at this issue for the last 4 days and I can’t seem to figure it out. I’m trying to send data to myself using UDP packets so another program can read the bytes.

I can clearly read the packets but I only get up to 3970 before the UDP portion of the program hangs. Glut and everything else continues to run fine. I gave my friend the same code and he ran it on his computer. He got 14386 iterations before it hangs. variable temp will count the number of packets sent. -1 is bad. counter counts the while loop iterations. I’m following the example here:

http://msdn.microsoft.com/en-us/library/ms740148(v=vs.85).aspx

Example Code:

#include "stdafx.h"
#include <WinSock2.h> // don't forget to add in 
//Project Properties>Linker>Input>Additional Dependences [Ws2_32.lib]
sockaddr_in dest;
sockaddr_in local;
WSAData data;
static void SUDP_init(void)
{
    printf("--[UDP Socket Initialized]--\r\n");
    WSAStartup( MAKEWORD( 2, 2 ), &data );

    local.sin_family = AF_INET;
    local.sin_addr.s_addr = inet_addr( "127.0.0.1" ); //same as localhost
    local.sin_port = 6000;

    dest.sin_family = AF_INET;
    dest.sin_addr.s_addr = inet_addr( "127.0.0.1" );
    dest.sin_port = htons( 6000 );

    bind( socket( AF_INET, SOCK_DGRAM, 0 ), (sockaddr *)&local, sizeof(local) );
    printf("Socket Bound...\r\n");
}
static int counter = 0;
int _tmain(int argc, _TCHAR* argv[])
{
    SUDP_init();
    while(1){
        char packet[30];
        sprintf(packet, "%0.3f,%0.3f,%0.3f", 
        55.4,
        16.1,
        -27.88);

        int temp = sendto( socket( AF_INET, SOCK_DGRAM, 0 ), packet, strlen(packet), 0, (sockaddr *)&dest, sizeof(dest) );
        if(temp>=1){
            counter++;
        }
        printf("Bytes Sent: %d, Counter: %d\r\n",temp,counter);
    }
    return 0;
}       
  • 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-23T11:14:26+00:00Added an answer on May 23, 2026 at 11:14 am

    You are allocating new sockets in a loop (the first argument to sendto), you are also allocating another for bind, but these are never freed. You eventually run out of socket handles to allocate, hence your program hanging.

    Instead, allocate a socket once in SUDP_init, store it instead of discarding it, then pass that to bind and sendto

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.