Home > Software engineering >  MFC application binding address failure?
MFC application binding address failure?

Time:09-22

 # include "winsock2. H" 
# pragma comment (lib, "ws2_32. Lib")
# define MAXNUM 20

The class CServerDlg: public CDialog
{
Public:
CIPAddressCtrl m_IP;
Int m_port;
Public:
The SOCKET m_server m_client;
The SOCKET m_Clients [MAXNUM];//client socket
Int m_CurClient;//the number of clients currently connected
Virtual void the HandleData ();
Virtual BOOL PreTranslateMessage * pMsg (MSG);

Public:
Cstrings m_serverIP;

};


Write the above is ServerDlg. H I defined in the content


In the left below is ServerDlg CPP OnOK function (for response to monitor button)
Void CServerDlg: : OnOK ()
{
//TODO: Add extra validation here

//the server address
Sockaddr_in serveraddr;
Serveraddr. Sin_family=AF_INET; Internal network protocol TCP/UDP//
M_IP. GetWindowText (m_serverIP);
//set the machine address
Serveraddr. Sin_addr. S_un. S_addr=inet_addr (m_serverIP);
The UpdateData (TRUE);
//set the port number
Serveraddr. Sin_port=htons (m_port);
//binding address
If (bind (m_server, (sockaddr *) & amp; Serveraddr, sizeof (serveraddr)))
{
MessageBox (" binding address failure ");
return;
}

//to start listening to
Listen (m_server, 50);
//CDialog: : OnOK ();


}


Problem is that no matter what I input the IP address, all show binding address, failure, what reason is this?
Left below is my dialog

From top to bottom respectively is CIPAddressCtrl m_IP and int m_port

CodePudding user response:

M_IP. GetWindowText (m_serverIP);
Are you sure this is executed, m_serverIP value is the IP address you entered?

CodePudding user response:

reference 1st floor happyparrot response:
m_IP. GetWindowText (m_serverIP);
Are you sure this is executed, m_serverIP value is the IP address you entered?


This statement is not mean it...

CodePudding user response:

What is not important, the important thing is the value right?

CodePudding user response:

Bind failure, to see if WSAGetLastError () what is the value?

CodePudding user response:

Please did you solve the problem? I also met,,

CodePudding user response:

Value is the MessageBox (m_IP) and port can be normal access to, WSAGetLastError () this value does not did not return any value

CodePudding user response:

M_server initialization?
The WSAStartUp call?
  • Related