Problem Sending UDP Packets
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Problem Sending UDP Packets

  1. #1
    Join Date
    Feb 2009
    Posts
    15

    Problem Sending UDP Packets

    Good Morning,

    I'm relatively new to socket communications. I'm trying to send a packet of data via UDP protocol on a WINCE device. Everything indicates that it is functioning properly (wsaStartup init, socket initialization, sendto returns # bytes I'm sending) except that I don't see the transmission of data when using WireShark to look at network comm. I see communication between the WINCE device (172.18.1.10) and my PC (172.18.1.2), but not from the following code:

    #include "stdafx.h"
    #include <windows.h>
    #include "WinSock2.h"

    int _tmain(int argc, _TCHAR* argv[])
    {
    WSADATA wsaData;
    int SenderSocket, sendResult, SenderPort = 12345;
    sockaddr_in SenderAddr;
    char sBuf[1200];

    // Initialize Windows side for Socket
    if(WSAStartup(MAKEWORD(2,2), &wsaData) != 0)
    {
    #ifdef _DEBUG
    TRACE( _T("Could not initialize sockets\n") );
    #endif
    return S_FALSE;
    }
    #ifdef _DEBUG
    TRACE( _T("Socket Initialized\n") );
    #endif

    // Create a Socket
    SenderSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
    if ( SenderSocket == INVALID_SOCKET )
    {
    #ifdef _DEBUG
    TRACE( _T("Send Socket Error\n") );
    #endif
    return S_FALSE;
    }

    // Fill in Port & IP Address Info
    SenderAddr.sin_family = AF_INET;
    SenderAddr.sin_port = htons(SenderPort);
    SenderAddr.sin_addr.s_addr = inet_addr("172.18.1.10");

    sBuf[0] = 'T';
    sBuf[1] = 'e';
    sBuf[2] = 's';
    sBuf[3] = 't';
    while ( 1 )
    {
    sendResult = sendto(SenderSocket, sBuf, 4, 0, (SOCKADDR *)&SenderAddr, sizeof(SenderAddr));
    Sleep(1000);
    }

    // Close Socket
    closesocket( SenderSocket );
    WSACleanup();

    return 0;
    }

    Please show me what I'm doing incorrectly.

    Thanks...

  2. #2
    Join Date
    Feb 2009
    Posts
    15

    Re: Problem Sending UDP Packets

    Problem solved - I was sending to the wrong IP address of 172.18.1.10

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center