Re: call is blocked in recvfrom() and no further proceedings in Wi



How is the Windows CE device connected to the network where the desktop
machine is? Don't say ActiveSync; that won't work with UDP. I don't have
any examples of datagram operations, except some for multicasting, sorry.

Paul T.

"Sudha.v" <Sudhav@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:EC61B1D6-D21D-4537-9F3F-B4BD42935A6D@xxxxxxxxxxxxxxxx
> Hi Paul,
> Thanks for ur reply. I have tested it on real device (Samsung). But no
> luck
> application is exiting when it reaches recvfrom().
>
> i=recvfrom(s1,packetbuffer,sizeof(packetbuffer),0,(SOCKADDR
> *)&addr,&cbRemoteAddrSize);
>
> This is the code I'm using. I changed many things from the previous code
> for
> testing purpose. Just have a look at the code and let me know u can find
> something on it.
> If there is any sample program for udp please let me know.
> Your help is greatly appreciated.
>
> Thanks,
>
>
>
> --
> Attempting half-heartedly is like expecting failure and achieving it.
>
>
> "Paul G. Tobey [eMVP]" wrote:
>
>> What happens on a *real device*. I don't trust the emulator for this
>> type
>> of thing. It's not a real device; its network stack is running on top of
>> the real stack on the PC, etc.
>>
>> Paul T.
>>
>> "Sudha.v" <Sudhav@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
>> news:D84E9754-AA07-45B1-845A-3EEAADA4D5E7@xxxxxxxxxxxxxxxx
>> > In the below code, application simply keeps on waiting for incoming
>> > data(Means, call is blocked in recvfrom() and no further proceedings).
>> > Environment : EVC++ 4.0, Smart phone 2003 SDK Emulator.
>> > Simple intro about the application.
>> > An NT service is running in my system(PC) which is nothing but the
>> > server.
>> > My program has to send request to service through port 5070(in this
>> > port
>> > only
>> > server is receiving the requests). Depending upon request, server will
>> > send
>> > response back to the program in port 5090. and application uses UDP.
>> > · So In the code, socket "s" will send request to NT service.
>> > · And "sock" will receive the response.
>> > · Everything seems to be OK. But during debugging the application
>> > infinitely
>> > waiting in recvfrom() call. This call is not at all returning.
>> > But the same code is working in windows. Only in Windows CE it is not
>> > working.
>> > In order to find whether data is available in the port or not, I have
>> > done
>> > the following.
>> > · Sent data from Windows CE(i.e., socket is created in EVC++ 4.0 to
>> > send
>> > request to NT service).
>> > · Received the response in Windows(means, for reception I created
>> > socket
>> > in
>> > VC++ 6.0 and data is successfully received).
>> > · From the above two steps, I'm clear that, data is available in the
>> > specific port (i.e, in 5090).
>> > So, the issue is in Windows CE, recvfrom() call is infinitely waiting
>> > and
>> > not returning even though the packet is available in the specific net
>> > work
>> > address.
>> > You may be annoyed of seeing this bulk of code. But I'm desperately in
>> > need
>> > of the solution. So, please have a look at the code. Your help is
>> > greatly
>> > appreciated.
>> >
>> > #include <stdio.h>
>> > #include <stdlib.h>
>> > #include <malloc.h>
>> >
>> > #include <windows.h>
>> > #include <windowsx.h>
>> > #include <winsock2.h>
>> > #include <ws2tcpip.h>
>> > #include <string.h>
>> > #define DEFAULT_FAMILY AF_UNSPEC
>> > #define DEFAULT_SOCKTYPE SOCK_DGRAM
>> > #define DEFAULT_PORT "5090"
>> > #define BUFFER_SIZE 23 // length of "WinCE
>> > Echo
>> > Test Packet"
>> > #define TIMEOUT_SECS 2
>> > #define TIMEOUT_USECS 0
>> > SOCKET sock = INVALID_SOCKET;
>> > int nFamily = DEFAULT_FAMILY;
>> > int nSockType = DEFAULT_SOCKTYPE;
>> > char szRemoteName[64] = "INFBA01803";
>> > char *szPort = DEFAULT_PORT;
>> > SOCKADDR_STORAGE ssRemoteAddr;
>> > int cbXfer, cbTotalRecvd, cbRemoteAddrSize;
>> > WSADATA wsaData;
>> > ADDRINFO Hints, *AddrInfo = NULL, *AI;
>> > char szRemoteAddrString[128];
>> > fd_set fdReadSet;
>> > TIMEVAL timeout = {TIMEOUT_SECS, TIMEOUT_USECS};
>> > char pRecvBuf[BUFFER_SIZE];
>> > struct ip_mreq mreq;
>> > SOCKET sock, SockServ[FD_SETSIZE];
>> > fd_set fdSockSet;
>> > int nNumSocks, nNumSocksCount;
>> > char pBuf[] = "WinCE Echo Test Packet";
>> > int iReceiveStatus;
>> >
>> > //Change these if required
>> > #define USERNAME "sudhagar" //TODO
>> > #define PWD "nopass" //TODO
>> > #define INV_TO "sandeep" //TODO
>> > #define IP_SERVER "172.29.12.154"//TODO
>> > #define PORT_SERVER "5070" //TODO
>> > TIMEVAL ReceiveTimeout;
>> > int iRC = 0;
>> > int iSendStatus = 0;
>> > int SIPlib_main()
>> > {
>> > int i=0,j=0,k,infop1;
>> > char *reg_dest,*inv_dest,*bhr= NULL ,*nnop1;
>> > int x=0,reg_id=-1;
>> > char tmp[200],locip[50];
>> > unsigned int addr2=0;
>> > osip_proxy_authorization_t *proxy_auth;
>> > int cbXfer, cbTotalRecvd, cbRemoteAddrSize;
>> > TCHAR *str;
>> > SOCKET s,s1;
>> > struct sockaddr_in addr,addr1;
>> > char packetbuffer[1200]={{'\0'}},packetbuffer1[1000]={{'\0'}};
>> > WSADATA dat ;
>> >
>> > ///////////////
>> > SOCKET SIPRTPSOC;
>> > struct sockaddr_in addr21;
>> > char nextnon1[50];
>> > char *buf2;
>> > buf2=(char*)malloc(8*sizeof(char));
>> > ///////////////
>> > //End of variable declarations
>> >
>> > if(WSAStartup(MAKEWORD(2,2), &wsaData))
>> > {
>> > return 1;
>> > }
>> > sock = INVALID_SOCKET;
>> > for(i = 0; i < FD_SETSIZE; i++)
>> > SockServ[i] = INVALID_SOCKET;
>> >
>> > // Get a list of available addresses to serve on
>> >
>> > memset(&Hints, 0, sizeof(Hints));
>> > Hints.ai_family = nFamily;
>> > Hints.ai_socktype = nSockType;
>> > Hints.ai_flags = AI_NUMERICHOST | AI_PASSIVE;
>> > if(getaddrinfo(NULL, szPort, &Hints, &AddrInfo))
>> > {
>> > OutputDebugString(TEXT("ERROR: Couldn't get resolve the server
>> > name/address!"));
>> > }
>> > nNumSocksCount = 0;
>> > for(AI = AddrInfo; AI != NULL; AI = AI->ai_next)
>> > {
>> > if (nNumSocksCount == FD_SETSIZE)
>> > {
>> > // getaddrinfo returned more addresses than we could use
>> > break;
>> > }
>> >
>> > if((AI->ai_family == PF_INET) || (AI->ai_family == PF_INET6)) //
>> > only want PF_INET or PF_INET6
>> > {
>> > SockServ[nNumSocksCount] = socket(AI->ai_family,
>> > AI->ai_socktype, AI->ai_protocol);
>> > if (SockServ[nNumSocksCount] != INVALID_SOCKET)
>> > {
>> > if (bind(SockServ[nNumSocksCount], AI->ai_addr,
>> > AI->ai_addrlen) == SOCKET_ERROR)
>> > closesocket(SockServ[nNumSocksCount]);
>> > else
>> > {
>> > OutputDebugString(
>> > TEXT("Socket 0x%08x ready for connection with
>> > %hs
>> > family, %hs type, on port %hs\r\n"),
>> > SockServ[nNumSocksCount],
>> > (AI->ai_family == AF_INET) ? "AF_INET" :
>> > ((AI->ai_family == AF_INET6) ? "AF_INET6" : "UNKNOWN"),
>> > (AI->ai_socktype == SOCK_STREAM) ? "TCP" :
>> > ((AI->ai_socktype == SOCK_DGRAM) ? "UDP" : "UNKNOWN"),
>> > szPort);
>> > nNumSocksCount++;
>> > }
>> > }
>> > }
>> > }
>> >
>> > freeaddrinfo(AddrInfo);
>> >
>> > if (nNumSocksCount == 0)
>> > {
>> > OutputDebugString(TEXT("ERROR: Unable to serve on any address.
>> > Error
>> > = %d\r\n"), WSAGetLastError());
>> > goto Cleanup;
>> > }
>> > //Initializing socket s for transmission
>> > s = socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP);
>> > memset(&addr,0,sizeof(struct sockaddr_in));
>> > addr.sin_family = PF_INET;
>> > addr.sin_addr.s_addr = inet_addr(IP_SERVER);//Server IP
>> > addr.sin_port = htons((short )atoi(PORT_SERVER));//(5 0 7 0); Server
>> > Listen
>> > Port
>> > //1st Transmission ( REGISTER )
>> > i=sendto(s,reg_dest,strlen(reg_dest),0,(struct sockaddr
>> > *)&addr,sizeof(struct sockaddr_in));
>> > NKDbgPrintfW(L"\nSent : %d bytes\n\n",i);
>> > if(i != strlen(reg_dest))
>> > {
>> > OutputDebugString(TEXT("ERROR: Couldn't send the data! error =
>> > %d\r\n"), WSAGetLastError());
>> > }
>> > // Wait for incomming data/connections
>> > nNumSocks = nNumSocksCount;
>> > FD_ZERO(&fdSockSet);
>> > for (i = 0; i < nNumSocks; i++) // want to check all available
>> > sockets
>> > FD_SET(SockServ[i], &fdSockSet);
>> > if (select(nNumSocks, &fdSockSet, 0, 0, NULL) == SOCKET_ERROR)
>> > {
>> > OutputDebugString(TEXT("ERROR: select() failed with error =
>> > %d\r\n"), WSAGetLastError());
>> > goto Cleanup;
>> > }
>> > for (i = 0; i < nNumSocks; i++) // check which socket is ready to
>> > process
>> > {
>> > if (FD_ISSET(SockServ[i], &fdSockSet)) // proceed for
>> > connected
>> > socket
>> > {
>> > FD_CLR(SockServ[i], &fdSockSet);
>> > if(nSockType == SOCK_STREAM)
>> > {
>> > cbRemoteAddrSize = sizeof(ssRemoteAddr);
>> > sock = accept(SockServ[i], (SOCKADDR*)&ssRemoteAddr,
>> > &cbRemoteAddrSize);
>> > if(sock == INVALID_SOCKET)
>> > {
>> > OutputDebugString(TEXT("ERROR: accept() failed with
>> > error = %d\r\n"), WSAGetLastError());
>> > goto Cleanup;
>> > }
>> > OutputDebugString(TEXT("Accepted TCP connection from
>> > socket
>> > 0x%08x\r\n"), sock);
>> > }
>> > else
>> > {
>> > sock = SockServ[i];
>> > OutputDebugString(TEXT("UDP data available on socket
>> > 0x%08x\r\n"), sock);
>> > }
>> > break; // Only need one socket
>> > }
>> > }
>> > // Receive data from a client
>> >
>> > cbTotalRecvd = 0;
>> > do
>> > {
>> > cbRemoteAddrSize = sizeof(ssRemoteAddr);
>> > cbXfer = recvfrom(sock, packetbuffer + cbTotalRecvd,
>> > sizeof(packetbuffer) - cbTotalRecvd, 0,
>> > (SOCKADDR *)&ssRemoteAddr, &cbRemoteAddrSize);
>> > cbTotalRecvd += cbXfer;
>> > } while(cbXfer > 0 && cbTotalRecvd < sizeof(packetbuffer));
>> >
>> > OutputDebugString(TEXT("SUCCESS - Received %d bytes from client
>> > %hs\r\n"), cbTotalRecvd, szRemoteAddrString);
>> > Cleanup:
>> > for(i = 0; i < nNumSocks && SockServ[i] != INVALID_SOCKET; i++)
>> > closesocket(SockServ[i]);
>> > if(sock != INVALID_SOCKET)
>> > {
>> > shutdown(sock, SD_BOTH);
>> > closesocket(sock);
>> > }
>> > WSACleanup();
>> > return 0;
>> >
>> > --
>> > Attempting half-heartedly is like expecting failure and achieving it.
>>
>>
>>


.



Relevant Pages

  • RE: call is blocked in recvfrom() and no further proceedings in Win CE
    ... In windows CE, I'm able to send a request but I'm unable to receive it. ... Create another socket & bind with server IP address. ... > My program has to send request to service through port 5070(in this port only ...
    (microsoft.public.windowsce.embedded)
  • Re: SetSockOpt with SO_REUSEADDR parameter
    ... So I create multiple UDP sockets with the same port to send data. ... happening is that you are throwing away the old socket and replacing it with the new ... When the second client is connecting to server, I still get the error code ...
    (microsoft.public.vc.mfc)
  • Re: Maximum sockets
    ... > occasionally receives a WSAEADDRINUSE error message after ... > tell Windows to allocate the port itself, ... This is not a socket problem, ... you call connectWindows assigns it to a unused port. ...
    (microsoft.public.win32.programmer.networks)
  • UDP DoS attack in Win2k via IKE
    ... This memo should clarify the issue discovered with the UDP DOS ... Sending of UDP traffic to port 500 UDP will cause windows to ... attacked host is an IPSec gateway). ...
    (Bugtraq)
  • Re: call is blocked in recvfrom() and no further proceedings in Win CE
    ... > In windows CE, I'm able to send a request but I'm unable to receive it. ... Create another socket & bind with server IP address. ... >> My program has to send request to service through port 5070(in this port ...
    (microsoft.public.windowsce.embedded)