📄 recv.cpp
字号:
#include <afx.h>
#include <winsock2.h>
//#pragma Comment(lib,"ws2_32")
int main()
{
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 0;
}
/* 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 0;
}
SOCKET socket1;
sockaddr_in add;
sockaddr_in cadd;
add.sin_addr.S_un.S_addr=htonl(INADDR_ANY);
add.sin_family=AF_INET;
add.sin_port=htons(60000);
socket1=socket(AF_INET,SOCK_DGRAM,0);
if(SOCKET_ERROR==bind(socket1,(SOCKADDR*)&add,sizeof(SOCKADDR)))
MessageBox(NULL,"wanle",0,0);
char pbuff[100];
memset(pbuff,0,100);
//CString str;
int len=sizeof(SOCKADDR);
while(1)
{
recvfrom(socket1,pbuff,100,0,(SOCKADDR*)&cadd,&len);
::MessageBox(NULL, pbuff,0,MB_ICONINFORMATION );}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -