Hello,

I'm at the end with my knowledge. In cradle and in emulator it is possible
to connect and to load the file but via GPRS it isn't. recv returns -1

please help please help

thanks in advance


WSADATA WSAData;
hostent *h = NULL;
SOCKET s = INVALID_SOCKET;
sockaddr_in name;
try
{
if(0 != WSAStartup(0x0101,&WSAData))
throw(_T("WSAStartup(0x0101,&WSAData))"));
/*wchar_t x[51];
wsprintf(x,_T("%i"),WSAData.wVersion);
SetDlgItemText(IDC_STATIC1,x);*/

hostent *h = gethostbyname("www.pilskills.de");
if(NULL == h)
throw(_T("could not resolve hostname"));



s = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(INVALID_SOCKET == s)
throw(_T("socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);"));

name.sin_port = htons(80);
name.sin_family = AF_INET;
memcpy(&name.sin_addr.S_un.S_addr,h->h_addr_list[0],sizeof(4));

if(0 != connect(s,(SOCKADDR*) &name, sizeof(name)))
throw(_T("connect(s,(SOCKADDR*) &name, sizeof(name))"));

if(SOCKET_ERROR == send(s, "GET /index.html\r\n\r\n",sizeof("GET
/index.HTML\r\n\r\n"),0))
throw(_T("send(s, \"GET /index.HTML\r\n\r\n\",sizeof(\"GET
/index.HTML\r\n\r\n\")"));

char recvBuf[1000];
int bytesRecv = -99;
bytesRecv = recv(s,recvBuf,sizeof(recvBuf),0);

wchar_t z[101];
wsprintf(z,_T("bytesRecv %i"),bytesRecv);
SetDlgItemText(IDC_STATIC1,z);
WriteToLog(recvBuf);



if(0 != shutdown(s,0))
throw(_T("shutdown(s,SD_BOTH))"));

if(0 != closesocket(s))
throw(_T("closesocket()"));


if(0 != WSACleanup())
throw(_T("WSACleanup()"));
}
catch(wchar_t *except)
{

SetDlgItemText(IDC_STATIC1,except);
}
catch(...)
{
SetDlgItemText(IDC_STATIC1,_T("unhandled exception"));
}

Re: SOCKETS by Trevor

Trevor
Thu Apr 28 16:26:25 CDT 2005

If you read the MSDN documentation for recv, it says that the function will
return SOCKET_ERROR (which happens to be -1). It then goes on to say that
you can call WSAGetLastError to find out more information. I recommend you
do this in your code and report the error WSAGetLastError returns. You can
see the error codes that recv returns online
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/wi
nsock/recv_2.asp) or you can just type in the WSAGetLastError in the "Error
Lookup" tool that comes with VC++. If you still need help you can post your
error#.

"Sylvester" <lists_sebastian@yahoo.de> wrote in message
news:%23ZmPYJATFHA.2560@TK2MSFTNGP09.phx.gbl...
> Hello,
>
> I'm at the end with my knowledge. In cradle and in emulator it is possible
> to connect and to load the file but via GPRS it isn't. recv returns -1
>
> please help please help
>
> thanks in advance
>
>
> WSADATA WSAData;
> hostent *h = NULL;
> SOCKET s = INVALID_SOCKET;
> sockaddr_in name;
> try
> {
> if(0 != WSAStartup(0x0101,&WSAData))
> throw(_T("WSAStartup(0x0101,&WSAData))"));
> /*wchar_t x[51];
> wsprintf(x,_T("%i"),WSAData.wVersion);
> SetDlgItemText(IDC_STATIC1,x);*/
>
> hostent *h = gethostbyname("www.pilskills.de");
> if(NULL == h)
> throw(_T("could not resolve hostname"));
>
>
>
> s = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
> if(INVALID_SOCKET == s)
> throw(_T("socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);"));
>
> name.sin_port = htons(80);
> name.sin_family = AF_INET;
> memcpy(&name.sin_addr.S_un.S_addr,h->h_addr_list[0],sizeof(4));
>
> if(0 != connect(s,(SOCKADDR*) &name, sizeof(name)))
> throw(_T("connect(s,(SOCKADDR*) &name, sizeof(name))"));
>
> if(SOCKET_ERROR == send(s, "GET /index.html\r\n\r\n",sizeof("GET
> /index.HTML\r\n\r\n"),0))
> throw(_T("send(s, \"GET /index.HTML\r\n\r\n\",sizeof(\"GET
> /index.HTML\r\n\r\n\")"));
>
> char recvBuf[1000];
> int bytesRecv = -99;
> bytesRecv = recv(s,recvBuf,sizeof(recvBuf),0);
>
> wchar_t z[101];
> wsprintf(z,_T("bytesRecv %i"),bytesRecv);
> SetDlgItemText(IDC_STATIC1,z);
> WriteToLog(recvBuf);
>
>
>
> if(0 != shutdown(s,0))
> throw(_T("shutdown(s,SD_BOTH))"));
>
> if(0 != closesocket(s))
> throw(_T("closesocket()"));
>
>
> if(0 != WSACleanup())
> throw(_T("WSACleanup()"));
> }
> catch(wchar_t *except)
> {
>
> SetDlgItemText(IDC_STATIC1,except);
> }
> catch(...)
> {
> SetDlgItemText(IDC_STATIC1,_T("unhandled exception"));
> }
>
>



Re: SOCKETS by Sylvester

Sylvester
Fri Apr 29 04:14:30 CDT 2005

I thought something is wrong with my code.....! WSAGetLastError() returns
10054 which means that the connection was reseted by peer.

But the same server is connectable over ssl and I can connect through ssl
successful. Another thing I'm experiencing is that on MDA2 it is posible to
connect over port 80 and on MDA3 it isn't.
But I think the MDA series is only for the german market, so it might be
difficult to get help.

Please help, it is very important

thanks in advance

regards Sylvester

"Trevor" <trevor@spam.com> schrieb im Newsbeitrag
news:Oldu0jDTFHA.3040@TK2MSFTNGP10.phx.gbl...
> If you read the MSDN documentation for recv, it says that the function
will
> return SOCKET_ERROR (which happens to be -1). It then goes on to say that
> you can call WSAGetLastError to find out more information. I recommend
you
> do this in your code and report the error WSAGetLastError returns. You
can
> see the error codes that recv returns online
>
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/wi
> nsock/recv_2.asp) or you can just type in the WSAGetLastError in the
"Error
> Lookup" tool that comes with VC++. If you still need help you can post
your
> error#.
>
> "Sylvester" <lists_sebastian@yahoo.de> wrote in message
> news:%23ZmPYJATFHA.2560@TK2MSFTNGP09.phx.gbl...
> > Hello,
> >
> > I'm at the end with my knowledge. In cradle and in emulator it is
possible
> > to connect and to load the file but via GPRS it isn't. recv returns -1
> >
> > please help please help
> >
> > thanks in advance
> >
> >
> > WSADATA WSAData;
> > hostent *h = NULL;
> > SOCKET s = INVALID_SOCKET;
> > sockaddr_in name;
> > try
> > {
> > if(0 != WSAStartup(0x0101,&WSAData))
> > throw(_T("WSAStartup(0x0101,&WSAData))"));
> > /*wchar_t x[51];
> > wsprintf(x,_T("%i"),WSAData.wVersion);
> > SetDlgItemText(IDC_STATIC1,x);*/
> >
> > hostent *h = gethostbyname("www.pilskills.de");
> > if(NULL == h)
> > throw(_T("could not resolve hostname"));
> >
> >
> >
> > s = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
> > if(INVALID_SOCKET == s)
> > throw(_T("socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);"));
> >
> > name.sin_port = htons(80);
> > name.sin_family = AF_INET;
> > memcpy(&name.sin_addr.S_un.S_addr,h->h_addr_list[0],sizeof(4));
> >
> > if(0 != connect(s,(SOCKADDR*) &name, sizeof(name)))
> > throw(_T("connect(s,(SOCKADDR*) &name, sizeof(name))"));
> >
> > if(SOCKET_ERROR == send(s, "GET /index.html\r\n\r\n",sizeof("GET
> > /index.HTML\r\n\r\n"),0))
> > throw(_T("send(s, \"GET /index.HTML\r\n\r\n\",sizeof(\"GET
> > /index.HTML\r\n\r\n\")"));
> >
> > char recvBuf[1000];
> > int bytesRecv = -99;
> > bytesRecv = recv(s,recvBuf,sizeof(recvBuf),0);
> >
> > wchar_t z[101];
> > wsprintf(z,_T("bytesRecv %i"),bytesRecv);
> > SetDlgItemText(IDC_STATIC1,z);
> > WriteToLog(recvBuf);
> >
> >
> >
> > if(0 != shutdown(s,0))
> > throw(_T("shutdown(s,SD_BOTH))"));
> >
> > if(0 != closesocket(s))
> > throw(_T("closesocket()"));
> >
> >
> > if(0 != WSACleanup())
> > throw(_T("WSACleanup()"));
> > }
> > catch(wchar_t *except)
> > {
> >
> > SetDlgItemText(IDC_STATIC1,except);
> > }
> > catch(...)
> > {
> > SetDlgItemText(IDC_STATIC1,_T("unhandled exception"));
> > }
> >
> >
>
>