Click to See Complete Forum and Search --> : Problem Sending UDP Packets


madeuxls
November 11th, 2009, 10:27 AM
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...

madeuxls
November 11th, 2009, 11:55 AM
Problem solved - I was sending to the wrong IP address of 172.18.1.10