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

  • Home
  • SEARCH
  • 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 974451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:26:20+00:00 2026-05-16T03:26:20+00:00

I’m writing a file transfer application in VC++(Server) using UDP. I came to know

  • 0

I’m writing a file transfer application in VC++(Server) using UDP. I came to know in winsock2, there are some functions which are useful in file transfer. Can anybody help me. I’m also looking for a sample application of TransmitPackets of winsock2 but not gettng. Please help me. Thank you.

  • 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-16T03:26:21+00:00Added an answer on May 16, 2026 at 3:26 am

    http://www.mycplus.com/source-code/c-source-code/udp-sender-and-receiver/

    http://www.winsocketdotnetworkprogramming.com/winsock2programming/winsock2advancedcode1e.html

    http://msdn.microsoft.com/en-us/library/ms740566%28VS.85%29.aspx

    Here is the sample application and source code which will help you.

    edited:

    Following is the sender function which take string, size of string, IP and Port and send packets over UDP.

    int sender(char cSendBuffer[], int iBufferSize, char cIP[], int iPort)
    {
        WSADATA wsaData;
        WSAStartup(MAKEWORD(2,2), &wsaData);
    
        char cBroadcast = '1';
        int iNumBytes = 0;
    
        struct sockaddr_in their_addr;
        struct hostent *he;
    
        SOCKET sock;
        sock = socket(AF_INET,SOCK_DGRAM,0);
    
        if(setsockopt(sock,SOL_SOCKET,SO_BROADCAST,&cBroadcast,sizeof(cBroadcast)) < 0)
        {
            printf("\n ----------------------------------------- \n");
            printf("Error in setting UDP option");
            printf("\n ----------------------------------------- \n");
            return 0;
        }//End if
    
        their_addr.sin_family      = AF_INET;
        their_addr.sin_port        = htons(iPort);
        //Target IP
        their_addr.sin_addr.s_addr = inet_addr (cIP);                       
    
        int iSentBytes =0;
    
        //Send bytes through socket
        iSentBytes = sendto(sock,cSendBuffer, iBufferSize,0,(sockaddr*)&their_addr,sizeof(their_addr));
    
        if( iSentBytes < 0)
        {
            printf("\n ----------------------------------------- \n");
            printf("Data Sending Error");
            printf("\n ----------------------------------------- \n");
            closesocket(sock);
            return 0;
        }//End if
    
        else
        {
            printf("\n ----------------------------------------- \n");
            printf("\n Data sent successfully to AT PORT:%d AND IP:%s \n",iPort,cIP);
            printf("\n ----------------------------------------- \n");
        }//End else
    
            closesocket(sock);
            WSACleanup();
            return 1;
    
    }//End Function For Sending Packet
    

    Following is the receiver function of UDP.

        int UDPReceiver( void )
        {
            char cRecievedBuffer[TRACK_BUFFER_SIZE];
    
            WSADATA wsaData;
            WSAStartup(MAKEWORD(2,2), &wsaData);
            SOCKET sock;
            sock = socket(AF_INET,SOCK_DGRAM,0);
    
            // my address information
            struct sockaddr_in  my_addr;
            // connector's address information
            struct sockaddr_in  their_addr;
    
            //sizeof (ANSI C function)
            int len = sizeof(struct sockaddr_in);
    
            my_addr.sin_family = AF_INET;
            my_addr.sin_port = htons(MYPORT);
    
            //Automatically fill with my IP
            my_addr.sin_addr.s_addr = INADDR_ANY;
    
            if (bind(sock,(sockaddr*)&my_addr, sizeof (my_addr)) < 0)
            {
                printf("\n ----------------------------------------- \n");
                printf(" Error in BINDING ");
                printf("\n ----------------------------------------- \n");
                return 0;
            }//End if
    
            while(recvfrom(sock,cRecievedBuffer,TRACK_BUFFER_SIZE,0,(sockaddr *)&their_addr,&len))
            {
    
    //Your Decoder code
    
           }
    
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.