UDP Client—Linux

#include <stdio.h>
#include <netinet/ip.h> int main(int argc,char *argv[])
{
#define PERCENT 100
#define THOUSAND 1000
int a = ;
int iSock = , tmpSock = ;
int opt = ;
int iRet = ;
int iRes = ;
int iFileDesc = ;
int iFileRet = ;
unsigned short usPeerPort = ;
char *pPeerIP = "192.168.1.100";
unsigned char pRecvBuff[];
unsigned char pSendBuff[] = "I'm Zynq ^_^";
time_t now;
struct tm *p;
unsigned int uiCnt = ;
unsigned int uiPeriod = ;
unsigned int uiSpeed = ;
unsigned int uiTmp = ;
char filePre[] = {};
char fileName[] = {};
char cmd[] = {};
struct sockaddr_in addrLocal, addrPeer;
static unsigned int s_uiLen = ; memset(pRecvBuff, 0x00, ); iSock = socket(AF_INET, SOCK_DGRAM, );
if (iSock < )
{
printf("Create socket error![%d]\n", iSock);
return ;
} //iRes = 1;
//ioctlsocket(iSock, FIONBIO, (u_long FAR*)&iRes); /* 设置本地的IP地址 */
addrLocal.sin_family = AF_INET;
addrLocal.sin_port = htons();
addrLocal.sin_addr.s_addr = htonl(INADDR_ANY);
//addrLocal.sin_addr.S_un.S_addr = inet_addr("10.10.22.100"); /* 设置远端的IP地址 --by cqs */
addrPeer.sin_family = AF_INET;
addrPeer.sin_port = htons(usPeerPort);
addrPeer.sin_addr.s_addr = inet_addr(pPeerIP); iRet = bind(iSock, (struct sockaddr *)&addrLocal, sizeof(struct sockaddr));
if (iRet < )
{
printf("bind error\n");
return ;
} iRet = sendto(iSock, (char *)pSendBuff, , , (struct sockaddr*)&addrPeer, sizeof(struct sockaddr));
if (iRet > )
{
printf("Udp send: %s\n", pSendBuff);
}
else
{
printf("Udp send error![%d]\n", iRet);
} return ;
}
上一篇:Javascript中call和apply的区别与详解


下一篇:BZOJ 1002 [FJOI2007]轮状病毒