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. Managed C++/CLI
  4. Socket Programming question

Socket Programming question

Scheduled Pinned Locked Moved Managed C++/CLI
questionhelptutorial
2 Posts 2 Posters 0 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.
  • M Offline
    M Offline
    mdykstra
    wrote on last edited by
    #1

    Hi, Being relatively new to socket programming, I need some assistance in sending and receiving data over a TCP connected socket. I'm familiar with using send and recv commands to send and recv buffered character data, but what about if I want to send and recv data formatted within a structure? For example, main () { struct { int data1; double data2; bool indicator; }msg; // initialize data msg.data1 = 0; msg.data2 = 5.8; msg.inidicator = false; // send data ..... // receive data ..... } Are the send and recv commands the right ones to use for this type of information to send and receive data over a TCP connected socket or are there other commands that are better suited for this. When I use the send(socketfd, (char *)&msg, 0), it "appears" to work, but when receiving the data using recv(socketfd, (char *)&msg, 0), it returns with a -1. Thanks in advance for any help. -Martin NB: The commands must work on both the Windows and UNIX side, so Windows specific commands wouldn't work.

    W 1 Reply Last reply
    0
    • M mdykstra

      Hi, Being relatively new to socket programming, I need some assistance in sending and receiving data over a TCP connected socket. I'm familiar with using send and recv commands to send and recv buffered character data, but what about if I want to send and recv data formatted within a structure? For example, main () { struct { int data1; double data2; bool indicator; }msg; // initialize data msg.data1 = 0; msg.data2 = 5.8; msg.inidicator = false; // send data ..... // receive data ..... } Are the send and recv commands the right ones to use for this type of information to send and receive data over a TCP connected socket or are there other commands that are better suited for this. When I use the send(socketfd, (char *)&msg, 0), it "appears" to work, but when receiving the data using recv(socketfd, (char *)&msg, 0), it returns with a -1. Thanks in advance for any help. -Martin NB: The commands must work on both the Windows and UNIX side, so Windows specific commands wouldn't work.

      W Offline
      W Offline
      willy_total
      wrote on last edited by
      #2

      you are sending 0 bytes. you need to give it a size that your are sending. You also need to give a size when you recv. It would work best if you just used sizeof(msg)

      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