概述
CODE:
#define _AFXDLL
#include "afx.h"
#include "mex.h"
#include
#include
#include
#pragma comment(lib, "ws2_32.lib")
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
main();
return;
}
int main(int argc, char* argv[])
{
WSADATA wsaData;
WORD sockVersion = MAKEWORD(2,2);
if(WSAStartup(sockVersion, &wsaData) != 0)
{
printf("WSAStartup error !");
return 1;
}
SOCKET serSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); //IPv4 Datagram数据报 UDP协议
if(serSocket == INVALID_SOCKET)
{
printf("socket error !");
return 1;
}
sockaddr_in serAddr; //指定IP和端口
serAddr.sin_family = AF_INET;
serAddr.sin_port = htons(2888);
serAddr.sin_addr.S_un.S_addr = INADDR_ANY;
if(bind(serSocket, (sockaddr *)&serAddr, sizeof(serAddr)) == SOCKET_ERROR)
{
printf("bind error !",WSAGetLastError());
//closesocket(serSocket);
return 1;
}
sockaddr_in remoteAddr;
int nAddrLen = sizeof(remoteAddr);
while (true)
{
char recvData[255];
int ret = recvfrom(serSocket, recvData, 255, 0, (sockaddr *)&remoteAddr, &nAddrLen);
if (ret > 0)
{
recvData[ret] = 0x00;
printf("接受到一个连接:%s rn", inet_ntoa(remoteAddr.sin_addr));
printf(recvData);
}
char * sendData = "一个来自服务端的UDP数据包n";
sendto(serSocket, sendData, strlen(sendData), 0, (sockaddr *)&remoteAddr, nAddrLen);
}
closesocket(serSocket);
WSACleanup();
return 0;
}
最后
以上就是粗犷银耳汤为你收集整理的matlab include cpp,MATLAB与C++混合编程 Mex 通不过的问题的全部内容,希望文章能够帮你解决matlab include cpp,MATLAB与C++混合编程 Mex 通不过的问题所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复