none
請問socket怎麼作? RRS feed

  • 問題

  • 各位達人們

     

    在開發手機程式時,小的些了一段程式,可以編譯,但在debug時,發現錯誤碼 10047、10042,請問世哪裡錯?

    麻煩指導,謝謝大家!! 

     

    vs2005+wm5+c++

     

     

    short port_number; //this is the port number
     struct sockaddr_in socket_structure; //provides the low-level TCP/IP socket structure
     SOCKET theClient;
     WORD version;
     WSADATA wsaData;
     int nret;
     version=MAKEWORD(1,1);
     SOCKADDR_BTH address;
        memset( &address, 0x00, sizeof(address) );

     nret=WSAStartup(version,&wsaData);
        int listen_fd,listen_opt=1;
         SOCKET s =socket(AF_INET,SOCK_RAW,BTHPROTO_RFCOMM);
        int ss = setsockopt(s,SOL_SOCKET, SO_REUSEADDR, (char *)&listen_opt, sizeof(listen_opt));
        int con = connect(s,(sockaddr*)&address, sizeof(address)); 

        這裡 con 為 -1 用getlasterror發現10047 
        
        //int con = connect(   s,  (LPSOCKADDR)&socket_structure,  sizeof(socket_structure));
        //nret=bind(s,(LPSOCKADDR)&socket_structure,sizeof(socket_structure));

        int wge = GetLastError();

        nret=listen(s,10); //up to 10 connections may be waiting at any one time to be accepted
        DWORD dwBufferLen[10] ;  DWORD dwBufferInLen = 1 ;  DWORD dwBytesReturned = 0 ; 
        int ws = WSAIoctl(s,SO_SSL_GET_PROTOCOLS ,&dwBufferInLen, sizeof(dwBufferInLen),  &dwBufferLen, sizeof(dwBufferLen),&dwBytesReturned , NULL , NULL );
        // SO_SEC_SSL

    2007年8月23日 上午 10:58