Home > Back-end >  MFC opencv display local images and video, it can display the wi-fi network transmission of video
MFC opencv display local images and video, it can display the wi-fi network transmission of video

Time:09-25


MFC + opencv can display local images and video, how to change can display the WIFI network transmission of video?

CodePudding user response:

Combined with CSocket processing network data, without considering the transmission medium (WIFI/twisted pair) it's all the same to you,

CodePudding user response:

By clicking on the "connect" button, to connect to the network, the following code, how to accept video streaming, cache??

Void CMFCApplication1link12Dlg: : OnBnClickedButton1 ()
{
//TODO: add the control notification handler code

Netconn ();
}

Int netconn ()
{
//the first step: load socket library function
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
WORD wVersionRequested;
WSADATA wsaData;
int err;

WVersionRequested=MAKEWORD (1, 1);

Err=WSAStartup (wVersionRequested, & amp; WsaData);

If (err!=0) {
return 0;
}

If (LOBYTE (wsaData wVersion)!=1 | |
HIBYTE (wsaData wVersion)!=1) {
WSACleanup();
return 0;
}
Int port=8086;
The SOCKET st=SOCKET (AF_INET, SOCK_STREAM, 0);//initialize the socket


Struct sockaddr_in addr.//define a structure of IP address
Memset (& amp; Addr, 0, sizeof (addr));
Addr. Sin_family=AF_INET;//addr structure properties may be defined as the TCP/IP address
Addr. Sin_port=htons (port);//convert local byte order to network byte order,
Addr. Sin_addr. S_addr=htonl (INADDR_ANY);//INADDR_ANY on behalf of all the address on this server

//to bind IP and server program
If (bind (st, (struct sockaddr *) & amp; Addr, sizeof (addr))==1)
{
//printf (" bind failed % s \ n ", the strerror (errno));
AfxMessageBox (_T (" bind failed!" ));
Return EXIT_FAILURE;
}

//server side began to listen,
If (listen (st, 20)==1)
{
//printf (" listen failed % s \ n ", the strerror (errno));
AfxMessageBox (_T (" listen failed!" ));
Return EXIT_FAILURE;
}
//client_st=0;//the client end socket
Struct sockaddr_in client_addr;//said to the client IP address
Memset (& amp; Client_addr, 0, sizeof (client_addr));
Int len=sizeof (client_addr);
//the accept blocks, until the client connect to come over, the accept returns the client socket descriptor

AfxMessageBox (_T (" open client!" ));
Client_st=accept (st, (struct sockaddr *) & amp; Client_addr, & amp; Len);
If (client_st==1)
{
//printf (" accept failed % s \ n ", the strerror (errno));
AfxMessageBox (_T (" accept failed!" ));
Return EXIT_FAILURE;
}

HANDLE myThread=CreateThread (NULL,
0,
LPTHREAD_START_ROUTINE recvsocket,
(VOID *) client_st,
0,
0);
Return EXIT_SUCCESS;
}



Void recvsocket (LPVOID lpParam)
{
LpParam int st=(int);


While (1)
{
Memset (s, 0, sizeof (s));
Int rc=recv (st, s, sizeof (s), 0).
If (rc & lt; If=0)//recv returns less than or equal to 0, represent the socket has been closed or wrong
break;


}
return;

}
  • Related