使用的是VS2008,arduino上的程序已调试成功,可以使用PC端的UDP调试软件正常调试,现在需要将字符串的发送程序嵌入到一个C程序中,在网上查了好半天未果,只好来求助,现在找到的可以编译成功的程序如下#include #include
#define SERVERPORT 6000 //服务端口号
#pragma comment(lib, "WS2_32.lib");
int udpsend(int argc, char *argv[])
{
//加载套接字库
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 2 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
/* Tell the user that we could not find a usable */
/* WinSock DLL. */
return -1;
}
/* Confirm that the WinSock DLL supports 2.2.*/
/* Note that if the DLL supports versions greater */
/* than 2.2 in addition to 2.2, it will still return */
/* 2.2 in wVersion since that is the version we */
/* requested. */
if ( LOBYTE( wsaData.wVersion ) != 2 ||
HIBYTE( wsaData.wVersion ) != 2 ) {
/* Tell the user that we could not find a usable */
/* WinSock DLL. */
WSACleanup( );
return -1;
}
//创建套接字
SOCKET sockClient = socket(AF_INET, SOCK_DGRAM, 0);
if (INVALID_SOCKET == sockClient)
{
printf("socket() called failed! The error code is: %d\n", WSAGetLastError());
return -1;
}
else
{
printf("socket() called succesful!\n");
}
SOCKADDR_IN addrServer;
addrServer.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
addrServer.sin_family = AF_INET;
addrServer.sin_port = htons(SERVERPORT);
//发送数据
sendto(sockClient, "Hello", strlen("Hello")+1, 0, (SOCKADDR*)&addrServer, sizeof(SOCKADDR));
//关闭套接字
closesocket(sockClient);
//终止套接字库的使用
WSACleanup();
Sleep(1000);
return 0;
}
请问int udpsend(int argc, char *argv[]) 中的argc,*argv[]分别代表什么?如何修改才能使其能发送我所需要的一个字符串,希望能得到指点,谢谢了。