I BIND the SOCKET server side code in the CPP file to run without any problems, but not a in MFC as button function, which is a great god can tell me what the problem ah, thank you very much, the code is as follows: Void CsocketserverDlg: : OnBnClickedButton1 () { WSADATA WSD. The SOCKET server. The SOCKET sClient; Int retVal; Char buf [64]. //initialize the Socket dynamic database If (WSAStartup (MAKEWORD (2, 2), & amp; WSD)!=0) { AfxMessageBox (_T (" WSAStartup failed! \ n ")); return ; } //create listens for Socket Server=socket (AF_INET SOCK_STREAM, IPPROTO_TCP); If (INVALID_SOCKET==server) { AfxMessageBox (_T (" socket failed! \ n ")); WSACleanup (); return ; } //setting up a server Socket address SOCKADDR_IN addrServ; AddrServ. Sin_family=AF_INET; AddrServ. Sin_port=htons (9990); AddrServ. Sin_addr. S_un. S_addr=htonl (INADDR_ANY); //bind socket RetVal=bind (server, (const sockaddr *) & amp; AddrServ, sizeof (SOCKADDR_IN)); If (SOCKET_ERROR==retVal) { AfxMessageBox (_T (" bind failed! \ n ")); Closesocket (server); WSACleanup (); return ; } //start listening RetVal=listen (server, 1); If (SOCKET_ERROR==retVal) { AfxMessageBox (_T (" litsen failed! \ n ")); Closesocket (server); WSACleanup (); return ; }
//TODO: add the control notification handler code }
CodePudding user response:
You want to go into the thread, listening is a blocking process, the main program in your button resistance is dead