源码如下:
         AfxSocketInit(NULL);
CSocket socketfd;
socketfd.Create(9999,SOCK_DGRAM);
char *buf = new char[200];
strcpy(buf,"affdsafd");
error = socketfd.SendTo(buf,10,9999,"127.0.0.1",0);
运行时返回错误为10038,查找msdn为
           WSAENOTSOCK: The descriptor is not a socket
哪位大哥能解释一下,3x

解决方案 »

  1.   

    if (AfxSocketInit(NULL) == 0)
       AfxMessageBox("Initializing socket failed");
    CSocket socketfd;
    if (socketfd.Create(9999,SOCK_DGRAM) == 0)
    {
       CString ErrorSatus.Format("Creating socket failed:%d", GetLastError());
       AfxMessageBox(ErrorStatus);
    }
       Char *buf = new char[200];
       strcpy(buf,"affdsafd");
       error = socketfd.SendTo(buf,10,9999,"127.0.0.1",0);
      

  2.   

    socketfd.SendTo(buf,10,9999,"127.0.0.1",0);
    不对吧,怎么发给自己呢?