Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Winsock send() problem

13 views
Skip to first unread message

esteb...@gmail.com

unread,
Apr 8, 2008, 9:33:39 AM4/8/08
to
Hello.. I am writing this message because i am runing out of ideas of
how to solve this problem. In a mobile device (win mobile 6) i run an
application in where some data (a "HELLO" string) is send to the
server. The problem is that i can connect to the server but the
send(...) method seem not to be working and no error is reported in
the client app (mobile device).
Here is the code (is very similar to the one in C:\Program Files
\Windows Mobile 6 SDK\Samples\Common\CPP\Win32\SockApp if you have
win
6 SDK installed):

HRESULT hr = E_FAIL;


WSADATA wsaData = {0};
SOCKET mySocket;
sockaddr_in clientService;
CHAR szDeviceIP[MAX_PATH] = "192.168.0.112";


INT bytesSent = SOCKET_ERROR;
INT iRet = 0;


BOOL fSockInitialized = FALSE;


CHAR sendbuf[25] = "Hello";


// Inicializo Winsock.
iRet = WSAStartup( MAKEWORD(2,2), &wsaData);
if(iRet != NO_ERROR )
{
hr = E_FAIL;
goto Exit;
}


fSockInitialized = TRUE;


// Creo socket
mySocket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(mySocket == INVALID_SOCKET )
{
iRet = WSAGetLastError();
hr = HRESULT_FROM_WIN32(iRet);
goto Exit;
}


clientService.sin_family = AF_INET;
clientService.sin_addr.s_addr = inet_addr(szDeviceIP);
clientService.sin_port = htons(4130);


// Conecto al Server
iRet = connect(mySocket, (SOCKADDR*) &clientService,
sizeof(clientService));
if(SOCKET_ERROR == iRet)
{
iRet = WSAGetLastError();
hr = HRESULT_FROM_WIN32(iRet);
goto Exit;
}


// Mando buffer
bytesSent = send(mySocket, sendbuf, sizeof(sendbuf), 0);
if(SOCKET_ERROR == bytesSent)
{
iRet = WSAGetLastError();
hr = HRESULT_FROM_WIN32(iRet);
goto Exit;
}


hr = S_OK;


Exit:
if (mySocket != NULL)
{
closesocket(mySocket);
}


if (fSockInitialized)
{
WSACleanup();
}


if (FAILED(hr))
{
/*Error*/
}


Ohhh.. one VERY important thing i forgot. The send() method seems to
be working ok if i run the app through the emulator (Windows Mobile 6
Professional Emulator). but it does not under the device :S ( an
Imate
JASJAR )

HELP!!!! Thanks.


0 new messages