# 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: