Hello Cactus-Hugger, I didn't post any piece of code because I was thinking that's a strange net problem. Well, let me fix the problem and explanations. The scenario is the same. Also I have rewrite my server and client recv/send codes to it's simples expression (to avoid more programming errors). That's the server recv function:
Code:
char bff[2000];
int nbl;
nbl=recv(s,bff,2000,0);
bff[nbl]='\0';
is a simple use of recv (I know that will have problems on bigger requests, but for that test that's right because on the client's send buffer is 1024 and sends all the data at once). now the server's end connection function:
Code:
bool closeConection(SOCKET s)
{
if(shutdown(s,SD_SEND)==SOCKET_ERROR) {return false;}
char bff[2000];
bff[0]='\0';
while(1)
{
int nnb=recv(s,bff,2000-1,0);
if(nnb==SOCKET_ERROR) {return false;}
else if(nnb!=0)
{
bff[nnb]='\0';
printf("\tRebuts %d bytes inesperats durant la desconexio:\n",nnb);
printf("%s\n\n",bff);
}
else {break;}
}
if(closesocket(s)==SOCKET_ERROR) {return false;}
return true;
}
and now the client send function:
Code:
WSADATA wsa;
SOCKET s;
SOCKADDR_IN servidor;
LPHOSTENT he;
if(WSAStartup(MAKEWORD(2,0),&wsa)!=0) {printf("Error 0\n");getch();return false;}
if(wsa.wVersion!=MAKEWORD(2,0)) {WSACleanup();printf("Error 1\n");getch();return false;}
s=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(s==INVALID_SOCKET) {WSACleanup();printf("Error 2\n");getch();return false;}
servidor.sin_family=AF_INET;
servidor.sin_addr.s_addr=inet_addr("172.16.0.4");
servidor.sin_port=htons(80);
if(connect(s,(SOCKADDR*)&servidor,sizeof(servidor))==SOCKET_ERROR)
{
WSACleanup();
printf("Error 3");
getch();
return false;
}
int bs,br;
char sb[1024],rb[100];
sprintf(sb,"POST /DIRSERV/resposta.txt HTTP/1.1\r\n");
strcat(sb,"Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*\r\n");
strcat(sb,"Referer: http://172.16.0.4\r\n");
strcat(sb,"Accept-Language: es\r\n");
strcat(sb,"Content-Type: application/x-www-form-urlencoded\r\n");
strcat(sb,"Accept-Encoding: gzip, deflate\r\n");
strcat(sb,"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)\r\n");
strcat(sb,"Host: 172.16.0.4\r\n");
strcat(sb,"Content-Length: 36\r\n");
strcat(sb,"Connection: Keep-Alive\r\n");
strcat(sb,"Cache-Control: no-cache\r\n\r\n");
printf("Envia HDR: ");
bs=send(s,sb,strlen(sb),0);
printf("%d bytes ok\n",bs);
printf("Envia PRM: ");
sprintf(sb,"txt0=Texte+0&txt1=Texte+1&sbm=Enviar\r\n");
bs=send(s,sb,strlen(sb),0);
printf("%d bytes ok\n",bs);
br=0;
printf("\nRebent resposta servidor...\n");
while(br!=SOCKET_ERROR)
{
br=recv(s,rb,100,0);
if(br==0 || br==WSAECONNRESET)
{
printf("\n\nConexio finalitzada.\n");
break;
}
if(br<0) {break;}
rb[br]='\0';
printf("%s",rb);
}
shutdown(s,SD_BOTH);
closesocket(s);
WSACleanup();
also the simple expresion for the send algorithm. the header for that request is the same I get from a request in MSIE to my server from the next html form:
Code:
<html><head></head><body>
<form action="http://172.16.0.4/DIRSERV/resposta.txt" method="POST">
<input type="text" name="txt0" value="Texte 0"><br>
<input type="text" name="txt1" value="Texte 1"><br><br>
<input type="submit" name="sbm" value="Enviar">
</form></body></html>
That's what I have been doing. First start my server on PC#1 (172.16.0.4), run MSIE on PC#2 (172.16.0.3), connect and load the form page (that page is in PC#1, the server reads the 'GET' statement from MSIE to get that page, and still no errors), click submit and my server can get all the data sended from MSIE running on PC#2. I'll attach an image at the end (image00).
Right, now I have the MSIE headers that work, so I create my client (as it appears at the sample code I've posted), run server on PC#1, client on PC#1 (the client sends the data directly, without web form), and on the server I get all the data. There's no errors here.
And in the next step is where I can't get the data. I run the server on PC#1, the client on PC#2 (the same headers as before, the same client program), and on server I don't get the final params, the data is break after the <crlf><crlf>. And still something alse: the server is able to read the file requested in the 'POST' statement and return it to the client, and in all the cases works well. After send the file (a simple text file of 18 bytes), the client is able to get it without problems, the server calls the 'closeConnection()' function and in that case I get the alert of 'Unexpected extra bytes received'. I'll attach an image of that at the end (image001).
Why the same header and the same client programs run diferently when the client isn't in the same pc that the server? And why MSIE don't give me that problem? Knowing that my server can understand MSIE (also I have tested it with NSN and also works well) I should think that the problem is with the client... but then if the problem is in the client, why a system PC#1SERVER/PC#1CLIENT works, and fails the system PC#1SERVER/PC#2CLIENT?
As you can see on the attached images, the first image is for the PC#1SERVER/PC#1CLIENT, and is exactly the same result for PC#1SERVER/PC#2MSIE. And the second image is the PC#1SERVER/PC#2CLIENT, the data is broken after the <crlf><crlf> (I have translated 'cr'->'<br>' and 'lf'->'<bn>'), so I can see
Code:
...Keep-Alive<br><bn><br><bn>
and after that nothing else, while in the first image you can see that I can get all the data. It seems strange to me, I haven't any idea of what's happening.
More explications: I have been testing it with the router's port 80 opened and closed, but the error is always the same.
I'll take a look at WireShark to see what I'm really doing.
Thank's
Niara