UINT MFCDlg server: C: recv1 (SOCKET a1)
{
While (TRUE)
{
SOCKADDR Client1.
Int size=sizeof (SOCKADDR);
Char * MSG="123456786456123 \ r \ n";
The SOCKET Client=accept (a1, & amp; Client1, & amp; The size);
Send (Client, MSG, strlen (MSG) + sizeof (char), NULL);
While (TRUE)
{
The recv (Client, (char *) & amp; Msg2 MAXBYTE, NULL);
}
}
}
Void MFCDlg server: C: OnBnClickedButton1 ()
{
HANDLE Thread1=CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE) recv1, (LPVOID) a1, 0, 0).
While (1)
{
The UpdateData (FALSE);
}
Closesocket (a1);
WSACleanup ();
}
And I also need to put the information obtained from the SOCKET (string), update to the MFC edit box msg1 cstrings, but there was a dilemma N
the condition of hard1. If you don't set recv1 to static member function can't call, but set a static member function the caller as a static member function can't access the static member variables MSG
2. My in the mind have millions of grass mud horse in the pentium!
CodePudding user response:
Start a thread, will be handed in this pointer is not over?HANDLE Thread1=CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE) recv1, (LPVOID) this, 0, 0).
CodePudding user response:
Thread parameter passing in the object pointer, and then call the corresponding function through this pointerCodePudding user response:
Still have to pay attention to add the necessary lock,CodePudding user response:
Have responded to the front, the form object (this) as a parameter passed to the thread function.CodePudding user response: