If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Hybrid View

winsock - send(...) return 0

hi,
i write an program which use sockets .
i create a socket ( mySocket=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP) ).
i connect it to remote server ( HTTP ).
i try to send some data to remote server . it works fine when my connection to Net is not very busy otherwise the "send(...)" function return 0 - that means no data was sent ( to be sure i can send data i use "select(...)" function before i use "send(...)" ) .
now , what should i do in this case ?
what i actually do : close the socket , create another socket etc. but this means a waste of time . should i try to send data using the same socket ?
since it is an HTTP server it may close the connection before i can send my data and it is important for me to know that this particular data reach to server .

Re: winsock - send(...) return 0

Seems normal, the printf() is printing s and r, which have both been initialised to 0.
if you want to return those from the function, you'll need to change them from by-value to by-reference.

If you changed that:
i'd expect it to return 4 on a Win32 build and 8 on a Win64 build since you are telling send() to send the sizeof(szSend) which is the size of a pointer, not the size of the text where that pointer is poiting to. You probably intended strlen(szSend) (or the unicode variant)?

Re: winsock - send(...) return 0

Codeguru forum is nice for it content, but so bad here you can't format your message with font size, code font, posting screens, tabs and other options.. All of it makes difficult to read somebody`s post. Also it has dynamicaly filling content by scripts. So uneasily always to push the button "Yes" or "No" if you have non-standart options of you browser. That is why I so thanks to you for answer!

after getnameinfo() succeeded it returns with hostname. No wonder all of code after it did not run. send and recv had not been called that is why r and s variables which shows total number of sent and recieved bytes are NULL.

I'm also removed call of getnameinfo() from the code because numeric remote host ip already passing to SData through the (char* ipv4,,,) argument. And so I don't understand why we need it to connect to remote web-server.

Originally Posted by OReubens

i'd expect it to return 4 on a Win32 build and 8 on a Win64 build since you are telling send() to send the sizeof(szSend) which is the size of a pointer, not the size of the text where that pointer is poiting to.

You was right! using sizeof(szSend) instead of strlen() or wcslen for the UNICODE it is a rough mistake although you can find some code examples in MSDN whith sizeof insted of strlen! So be careful with that!

Now everything works fine. I can send the data to server and server answer me. For example if I sending the request "GET /automation/n09230945.asp HTTP/1.1\r\n host: www.whatismyip.com\r\n\r\n" to 72.233.89.197 ip (it is whatismyip.com domain) it response with http header and show me my public ip.

I'm not strong in WEB-programming so judge no lest ye be judged.
I know only one request GET If you know more requests please show me small examples. Or you can answer me what else I can talk about with any random server ?? Ah

Originally Posted by OReubens

Seems normal, the printf() is printing s and r, which have both been initialised to 0.
if you want to return those from the function, you'll need to change them from by-value to by-reference.

Yes, EXACTLY! not by-value, but by-reference. Don't know how. Show me please if you can. I want. And thank you very much (indeed) for your answer. Let the god bless you.