I am new to c++ and I am trying to send some data from UDP client to the socket and later take down that data in Matlab. I have downloaded some c++ code for visual studio and the program runs as MFC application. I need to click "send" to send the data. Can someone please help me to make the code below run as a an win32 console application. Thanks.
//This tutorial was written by Gil Dabah and Oren Becker
//QSoft Copyright(C) 1997-2000
//UDP sample client/server.
//
http://qsoft.cjb.net
#include <windows.h>
#include "resource.h"
//#define APP_PORT 0x1983
#define APP_PORT 3333
SOCKADDR_IN remote;
SOCKET sock;
BOOL CALLBACK DialogProc(HWND hDlg, UINT MSG, WPARAM wParam, LPARAM lParam)
{
switch(MSG)
{
case WM_COMMAND:
{
switch(wParam)
{
case IDC_SEND:
{
char buffer[256];
memset(buffer, '\0', sizeof(buffer));
GetDlgItemText(hDlg, IDC_MESSAGE, buffer, sizeof(buffer)-1);
int len = sizeof(SOCKADDR);
sendto(sock, buffer, strlen(buffer), 0, (SOCKADDR *)&remote, sizeof(SOCKADDR));
}break;
case IDC_OK:
case IDC_CANCEL: EndDialog(hDlg, 0); break;
}
}break;
}
return(0);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
WSADATA data;
if (WSAStartup(MAKEWORD(2,2), &data) != 0) return(0);
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (!sock)
{
WSACleanup();
return(0);
}
remote.sin_family = AF_INET;
remote.sin_addr.s_addr = inet_addr("127.0.0.1");
remote.sin_port = htons(APP_PORT);
DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DialogProc);
closesocket(sock);
WSACleanup();
return(1);
}