send() and recv() sockets
-
I have to use these plain sockets, not MFC. If I do one send() from one app, the other can get it with recv. This works. What I really need to do is write a number of separate chunks to a socket, then have the other one read it at its leisure. I tried write() but that doesnt work....it doesnt like the socket handle I get from socket(). So I tried two sends in one and two recvs in the other thinking that my multiple sends will get queued up and the other can recv the info at its leisure in measured doses eg. 1. send the header 2. send the image -------------------- 1 recv the header 2. recv the image If I have two sends and only 1 recv I can get the two things sent in the buffer that recv() has. However i really need to recv() stuff into separate buffers. I thought read and write would work, but it doesnt. How do I do this, so that I can recv stuff sent in two sends into two recv() buffers? Do I have to do an communication between processes? Like send 1 thing, wait and get a confirm from the other app on receipt, then send my second chunk which the other app will now be waiting for? send() 1st chunk recv() -- other app got it, so send again send() 2nd chunk while on the other end I have: recv() 1st chunk send() -- to tell its okay to send second chunk recv() second chunk..... I was hoping I could just read my two chunks and just send() them one after another.... Thanks, sb
-
I have to use these plain sockets, not MFC. If I do one send() from one app, the other can get it with recv. This works. What I really need to do is write a number of separate chunks to a socket, then have the other one read it at its leisure. I tried write() but that doesnt work....it doesnt like the socket handle I get from socket(). So I tried two sends in one and two recvs in the other thinking that my multiple sends will get queued up and the other can recv the info at its leisure in measured doses eg. 1. send the header 2. send the image -------------------- 1 recv the header 2. recv the image If I have two sends and only 1 recv I can get the two things sent in the buffer that recv() has. However i really need to recv() stuff into separate buffers. I thought read and write would work, but it doesnt. How do I do this, so that I can recv stuff sent in two sends into two recv() buffers? Do I have to do an communication between processes? Like send 1 thing, wait and get a confirm from the other app on receipt, then send my second chunk which the other app will now be waiting for? send() 1st chunk recv() -- other app got it, so send again send() 2nd chunk while on the other end I have: recv() 1st chunk send() -- to tell its okay to send second chunk recv() second chunk..... I was hoping I could just read my two chunks and just send() them one after another.... Thanks, sb
Question 1: is this TCP or UDP? if UDP, each send() requires one recv() on the other end. if TCP, things may get combined, or split. [you're not doing plain old IP, are you?] You should also look into a function: "WSASend" and "WSARecv" (these are microsoft re-implementations of send() and recv() that provide some extra capabilities, like sending chunks) Additionally, I'd recommend that you develop a data format. Some sort of additional data that you include your data with -- to add descriptive information into the packet/stream. Describing how bit it is, and what it is. That way, when it get's to the other side, you can tell what's going on, or what's missing.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Peter Weyzen Staff Engineer [Santa Cruz Networks](http://www.santacruznetworks.com)