CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 67

Threaded View

  1. #1
    Join Date
    Mar 2012

    getting a binding error in server program

    i created a client server program in MFC but when i run the server the error message "ERROR binding in the server socket" displays.
    this is the first time i am using code like this so I don't know how to fix this error.

    here is the code:
    void CSocketTestServerDlg::StartServer()
        WORD w = MAKEWORD(1,1);
        WSADATA wsadata;
        ::WSAStartup(w, &wsadata);
    	char opt = 1; 
    	setsockopt(m_serversocket, SOL_SOCKET, SO_BROADCAST, (char*)&opt, sizeof(char));
    	SOCKADDR_IN brdcastaddr;
        int portno = 1818;
        memset(&brdcastaddr,0, sizeof(brdcastaddr));
        brdcastaddr.sin_family = AF_INET;
        brdcastaddr.sin_port = htons(portno);
        brdcastaddr.sin_addr.s_addr = INADDR_BROADCAST;
    	m_serversocket = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
        if(m_serversocket == -1)
            AfxMessageBox("Socket Initialiation Error");
         int len = sizeof(brdcastaddr);
        char sbuf[1024];
        int ret = sendto(m_serversocket, sbuf, strlen(sbuf), 0, (sockaddr*)&brdcastaddr, len);
        if(ret < 0)
             AfxMessageBox("ERROR binding in the server socket");
        if(listen(m_serversocket,0) < 0)
             AfxMessageBox("ERROR listening in the server socket");
        SetTimer(0x01, 100, NULL);
    Last edited by beginner91; March 19th, 2013 at 06:26 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)