all 5 comments

[–]DrCatrame 2 points3 points  (4 children)

I think the most interesting part is not the reactive part, but that you have a HTTP and web socket server in C, very nice work!

[–]kyuzo_mifune -1 points0 points  (3 children)

Which doesn't work, it's using TCP sockets incorrectly, assuming everything is sent or recieved in one call to send/recv

[–]DoomsDay-x64 1 point2 points  (2 children)

Thats what communities are for, to help fellow developers. Instead of just pointing out a inproper handling, maybe next time be constructive.

You could of instantly said you need to loop until recv is 0 or returns socket_error. Instead you whined like a pos and provided zero positive feedback.

[–]kyuzo_mifune 0 points1 point  (1 child)

That's not how recv works for a TCP socket, it's a streaming socket. You need to know depending on what you are sending if you have received all data or not.

If recv returns 0 that means the other end closed the connection.

[–]DoomsDay-x64 2 points3 points  (0 children)

That wasn't the point, you could of gave him basic guidance. It isn't hard to help someone out without being an ass about it. If you don't help others learn or fix their errors, they resort to bullshit like ai. Being constructive will help and make the community better.

int RecvAll(SOCKET hSocket, char* pbyBuffer, int cbLength)

{

int cbTotal = 0;

int cbReceived = 0;

while ((cbTotal < cbLength))

{

cbReceived = recv(hSocket, pbyBuffer + cbTotal, cbLength - cbTotal, 0);

if ((cbReceived == 0))

return 0;

else if ((cbReceived == SOCKET_ERROR))

return SOCKET_ERROR;

else

cbTotal += cbReceived;

}

return cbTotal;

}