Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. send() and recv() sockets

send() and recv() sockets

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++
2 Posts 2 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    ns
    wrote on last edited by
    #1

    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

    P 1 Reply Last reply
    0
    • N ns

      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

      P Offline
      P Offline
      Peter Weyzen
      wrote on last edited by
      #2

      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)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups