报错的那段代码如下:void CChatRoomDlg::OnBtnSTATRSrv_CLicked()    
{
m_ListenSocket=(AF_INET,SOCK_STREAM,IPPROTO_TCP); //对监听端口的初始化
if (m_ListenSocket=INVALID_SOCKET)
{
AfxMessageBox(_T("新建SOCKET失败!"));
return;
}
UINT uPort=GetDlgItemInt(IDC_EDIT_LOCALPORT2);
if(uPort<=0||uPort>65535)
{
AfxMessageBox(_T("请输入正确的端口号:1-65535"));
goto _Error_Exit;
}
SOCKADDR_IN addrSrv;
addrSrv.sin_family=AF_INET;
addrSrv.sin_port=htons(uPort);
addrSrv.sin_addr.S_un.S_addr=INADDR_ANY;

if(bind(m_ListenSocket,(SOCKADDR*)&addrSrv,sizeof(addrSrv))==SOCKET_ERROR)
{
AfxMessageBox(_T("绑定端口失败!"));
goto _Error_Exit;
}
if (listen(m_ListenSocket,5)==SOCKET_ERROR)
{
AfxMessageBox(_T("监听端口失败!"));
goto _Error_Exit;
} sockaddr_in clientAddr;
int iLen = sizeof(SOCKADDR_IN);

SOCKET accpsock = accept(m_ListenSocket,(struct SOCKADDR *)&clientAddr,&iLen); //存在错误。
if (accpsock==INVALID_SOCKET)
{
AfxMessageBox(_T("接受客户端失败!"));

goto _Error_Exit;
}

   _Error_Exit:
closesocket(m_ListenSocket); //关闭socket
}报错如下:
C:\Documents and Settings\Administrator\桌面\调试文件\ChatRoom\ChatRoomDlg.cpp(360) : error C2664: 'accept' : cannot convert parameter 2 from 'struct CChatRoomDlg::OnBtnSTATRSrv_CLicked::SOCKADDR *' to 'struct sockaddr *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast有哪位大侠帮下吗!!

解决方案 »

  1.   

    SOCKET accpsock = accept(m_ListenSocket,(struct SOCKADDR *)&clientAddr,&iLen); //存在错误。
    -->SOCKET accpsock = accept(m_ListenSocket,(struct sockaddr *)&clientAddr,&iLen); 
      

  2.   

    typedef struct sockaddr SOCKADDR;
    SOCKET accpsock = accept(m_ListenSocket,(struct SOCKADDR *)&clientAddr,&iLen); //存在错误。
    -->
    SOCKET accpsock = accept(m_ListenSocket,(struct sockaddr *)&clientAddr,&iLen); 
    或者
    SOCKET accpsock = accept(m_ListenSocket,(SOCKADDR *)&clientAddr,&iLen);   
    这里
    if (m_ListenSocket=INVALID_SOCKET)
    {
    AfxMessageBox(_T("新建SOCKET失败!"));
    return;
    }