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.