locked
why am I not able to access the host PCs network through active synk? with one of my devices other work ok RRS feed

  • Question

  • I have an IHP 214 connected via USB to my development pc however when I try to use my application to use the development pcs network connection it does not connect however I also have a SPV M700 when I use this device it can access the network over active sink. As can the emulator.

     

    I have the flowing key set in the registry for active synk [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows CE Services]

    "GuestOnly"=dword:00000001

     

    Thursday, April 23, 2009 11:13 AM

Answers

All replies

  • Hi ceebmoj,

    Can you show how your application access the network, you also mentioned emulator also can access the network of the host pc, can you elaborate on it?





    Best regards,
    Guang-Ming Bian - MSFT
    Please remember to mark the replies as answers if they help and unmark them if they provide no help
    Monday, April 27, 2009 6:23 AM
  • hi there,

    im using the folowing code. when I run the emulater on the development pc and eather cradle the emulator or set up a net work conection that functions fine when I conect the ihp 214 and cradle that it can not conect to the network. 


    BOOL cAskSever::Ask(char* Question, char* ResultsBuffer, uint ResultsBufferSize, DWORD* ResultsLength)
    {
        int TimeOutCount = 0;
    sockaddr_in mSocketAdress;
    WSAEVENT hEvent;
    WSANETWORKEVENTS NetworkEvent;
    DWORD dwSize = 0, dwRecu = 0, dwEcrit = 0, dwEcritTotal = 0;

        
        memset (ResultsBuffer, ' ', ResultsBufferSize);

        //initialise wsa
    WSADATA wsa;
    if(WSAStartup(0x0202, &wsa))
    {
            cMessage::Instance()->Log(MERROR, L"Ask Server WSA Initialization");
    return FALSE;
    }

    // I: initialisation de la connexion
        // I: initialization of connection
    SOCKET mSocket = socket(AF_INET, SOCK_STREAM, 0);
    if(mSocket == INVALID_SOCKET)
            cMessage::Instance()->Log(MERROR, L"Ask Server Socket (%d)", WSAGetLastError());
            CloseSocket(mSocket,&hEvent);
            mStatusCode = SocketInvalid;
    return FALSE;
    }

    mSocketAdress.sin_family           = AF_INET;
    mSocketAdress.sin_port             = htons(80);
        mSocketAdress.sin_addr.S_un.S_addr = GetServerAddress(pNetVuConnectedCommand->GetSever()->URL);

    hEvent = WSACreateEvent();
    WSAEventSelect(mSocket, &hEvent, FD_READ | FD_CONNECT | FD_CLOSE | FD_OOB);

    connect(mSocket, (sockaddr*)&mSocketAdress, sizeof(mSocketAdress));

    while(TimeOutCount<MAXIMUM_TIMEOUTS)
    {
    memset(&NetworkEvent, 0, sizeof(NetworkEvent));

    WSAWaitForMultipleEvents(1, &hEvent, 0, WSA_WAIT_TIMEOUT, 0);
    WSAEnumNetworkEvents(mSocket, hEvent, &NetworkEvent);

            LogNetworkEvent(NetworkEvent.lNetworkEvents);
           
    if(NetworkEvent.lNetworkEvents & FD_CONNECT)
    {
                // error with socket connection
    if(NetworkEvent.iErrorCode[FD_CONNECT_BIT])
    {
                    cMessage::Instance()->Log(MERROR, L"Ask Server Socket connection");
                    CloseSocket(mSocket,&hEvent);
                    mStatusCode = SocketConnectionError;
                    return FALSE;
    }

                send(mSocket, Question, strlen(Question), 0);
    }

    if(NetworkEvent.lNetworkEvents & FD_READ)
    {
    int err = 0;
    dwRecu = 0;
    int iHeaderLen = 0;
    UINT8 retrys = 0;

    // wait until device is ready
    Sleep(500);
    do
                {
    dwRecu = recv(mSocket,ResultsBuffer, ResultsBufferSize, 0);

    if(dwRecu == SOCKET_ERROR)
    {
    retrys++;
    err = WSAGetLastError();
    Sleep(100);
    }
    else
    {
    break;
    }
    } while(err == WSAEWOULDBLOCK && dwRecu == SOCKET_ERROR && retrys < MAXIMUM_RETRYS);

                
    // téléchargement fini
                // finished remote loading
    if(dwRecu > 0)
    {
                    if(dwRecu!=SOCKET_ERROR)
                    {
                        ResultsBuffer[dwRecu] = '\0';
                        iHeaderLen = StripHeaderHttp(ResultsBuffer, ResultsBufferSize);
       *ResultsLength = (dwRecu-iHeaderLen);                

                        CString Results;
                        if(iHeaderLen!=0)
                        { 
                            
                            Results.Format(L"%S", ResultsBuffer);
                            cMessage::Instance()->Log(MINFO, L"Ask Server data size %d data '%s'",*ResultsLength, Results);

                            CloseSocket(mSocket,&hEvent);
           return TRUE;
                        }
                        else
                        {
                            cMessage::Instance()->Log(MERROR, L"No header found");
                            CloseSocket(mSocket,&hEvent);
                            mStatusCode = NoHTTPHeaderFound;
           return FALSE;
                        }
                    }
                    else
                    {
                        cMessage::Instance()->Log(MERROR, L"Socket error");
                        CloseSocket(mSocket,&hEvent);
                        mStatusCode = SocketError;
       return FALSE;
                    }
    }
    else
    {
    cMessage::Instance()->Log(MERROR, L"Download complete nothing returned");
                    CloseSocket(mSocket,&hEvent);
                    mStatusCode = DownloadCompleteNothingReturned;
                    return FALSE;
    }
    }

    if(NetworkEvent.lNetworkEvents & FD_CLOSE)
    {
    // verifie s'il ne reste plus rien a lire sur le socket
                // check s' there remain nothing any more has to read on the socket
    do 
    {
    memset(&NetworkEvent, 0, sizeof(NetworkEvent));
    WSAEnumNetworkEvents(mSocket, 0, &NetworkEvent);
    if(NetworkEvent.lNetworkEvents & FD_READ)
    {
    dwRecu = 0;
    dwRecu = recv(mSocket,ResultsBuffer, ResultsBufferSize, 0);
    if(dwSize == dwEcritTotal) break;
    }
    } while(NetworkEvent.lNetworkEvents & FD_READ);

    if(dwSize == dwEcritTotal)
    {
    //cMessage::Instance()->Log(L"Finished remote loading(%d)", dwSize);
    ResultsBuffer[dwSize] = '\0';
                    *ResultsLength = dwSize;
                    CloseSocket(mSocket,&hEvent);
                    return TRUE;
    }
    else
    {
    cMessage::Instance()->Log(MERROR, L"Disconnected from the server");
                    CloseSocket(mSocket,&hEvent);
                    mStatusCode = Disconnected;
                    return FALSE;
    }
    }
            TimeOutCount++;
    }

        if(TimeOutCount>=MAXIMUM_TIMEOUTS)
        {cMessage::Instance()->Log(MERROR,L"Ask sever timed out");}

        //belts and braces 
        CloseSocket(mSocket,&hEvent);
        mStatusCode = Timeout;
    return FALSE;
    }


    DWORD cAskSever::GetServerAddress(CString URL)
    {
        //CString IPAddress;
        hostent * server = NULL;

        //strip out formating 
        URL.Replace(L"http://", NULL);

        //strip user and id from IP addres if it exsists
        //for(int i =0; i<URL.GetLength(); i++)
        //{
        //    if(URL.GetAt(i) == '@')
        //    {
        //        URL = URL.Right(URL.GetLength()-(i+1));
        //        i = URL.GetLength();
        //    }
        //}

        //look at server = getaddrinfo()
        char buffer[MAXBUFFER];
        if(MAXBUFFER>URL.GetLength())
        {
            sprintf(buffer,"%S",URL);
            if(IsIPAddress(URL))
            {
                unsigned long SocketAddress = inet_addr(buffer);

                if(INADDR_NONE == SocketAddress || INADDR_ANY == SocketAddress)
                { 
                    cMessage::Instance()->Log(MWARRNING, L"Ask Server Failed to resolve socket address for %s",URL);
                    return 0; 
                }

                cMessage::Instance()->Log(MINFO, L"Ask Server IP address %s Resolves to socket address %d", URL, SocketAddress); 
                return SocketAddress;
            }
            else
            {   
                server = gethostbyname(buffer);
                if(server == NULL)
                {
                    cMessage::Instance()->Log(MWARRNING, L"Ask Server Failed to resolve host name for %s", URL);
                    return 0;
                }
                cMessage::Instance()->Log(MINFO, L"Ask Server Host Name %s resolves to socket address %d", URL, (DWORD)*((DWORD*)server->h_addr_list[0]));
                return (DWORD)*((DWORD*)server->h_addr_list[0]);
            }
        }
        return 0;
    }
    Monday, April 27, 2009 8:06 AM
  • Hi ceebmoj,

    Base on my understanding, you want to do socket communication between device and desktop via activesync. If I have misunderstood you, please let me know, thanks.

    As far as I know, activesync connection will get an IP :169.254.2.1,  you can try following step:
    1. Start--Settings--Connections--USB to PC, you will see a checkbox, if it is not checked, please check it.

    Please also keep in mind  not all the devices support it, some devices deosn't provide the function.

    You can take look at some similar threads which may give you more information:
    http://social.msdn.microsoft.com/forums/en-US/windowsmobiledev/thread/cd8f4939-d9a2-4485-8b1e-4c35b1e090dd/
    http://social.msdn.microsoft.com/forums/en-US/netfxcompact/thread/b53de52c-a8ee-47f5-9eea-e1c37d02ced5/


    Best regards,
    Guang-Ming Bian - MSFT



    Please remember to mark the replies as answers if they help and unmark them if they provide no help
    Wednesday, April 29, 2009 3:13 AM