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. Socket Programming

Socket Programming

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminhelp
6 Posts 4 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.
  • U Offline
    U Offline
    User 900278
    wrote on last edited by
    #1

    Hello Freinds, I want to transfere one structure from client to server. structure contains one String and INT data, INT is the length of that string. I am trying send(); function of CSocket to transfere the structure but I am getting some garbage at server end and missing my strings address. Can anyone pl's help me. I have dought that the function I am using may not be currect. Thanks. Dinesh.

    T R M 3 Replies Last reply
    0
    • U User 900278

      Hello Freinds, I want to transfere one structure from client to server. structure contains one String and INT data, INT is the length of that string. I am trying send(); function of CSocket to transfere the structure but I am getting some garbage at server end and missing my strings address. Can anyone pl's help me. I have dought that the function I am using may not be currect. Thanks. Dinesh.

      T Offline
      T Offline
      ThatsAlok
      wrote on last edited by
      #2

      why don't you directly transfered the string to the server!,as recv winsock api returnd with total length of data recieved. something like this way, i am giving win32 based code Client End:

      char szString="Codeproject";
      UINT nszLen=strlen(szString)+1;//Extra NULL character
      send(hSendingSocket,szString,nszLen,0);

      Server End

      char szString[1024];
      int nTotalBufferLen=1023;//one for NULL character

      //recv data
      int nRecv=recv(hRecvingSocket,szString,nTotalBufferLen,0);

      //complete string
      szString[nRecv]=NULL;


      "I Think this Will Help" [Vote One Here,.....]

      visit me at http://www.thisisalok.tk
      1 Reply Last reply
      0
      • U User 900278

        Hello Freinds, I want to transfere one structure from client to server. structure contains one String and INT data, INT is the length of that string. I am trying send(); function of CSocket to transfere the structure but I am getting some garbage at server end and missing my strings address. Can anyone pl's help me. I have dought that the function I am using may not be currect. Thanks. Dinesh.

        R Offline
        R Offline
        Ravi Bhavnani
        wrote on last edited by
        #3

        Dinesh, I recommend using CSocketFile and CArchive. They work beautifully! :cool: /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

        U 1 Reply Last reply
        0
        • R Ravi Bhavnani

          Dinesh, I recommend using CSocketFile and CArchive. They work beautifully! :cool: /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

          U Offline
          U Offline
          User 900278
          wrote on last edited by
          #4

          Thanks Ravi, I will try this option. Dinesh.

          1 Reply Last reply
          0
          • U User 900278

            Hello Freinds, I want to transfere one structure from client to server. structure contains one String and INT data, INT is the length of that string. I am trying send(); function of CSocket to transfere the structure but I am getting some garbage at server end and missing my strings address. Can anyone pl's help me. I have dought that the function I am using may not be currect. Thanks. Dinesh.

            M Offline
            M Offline
            Mohammad A Gdeisat
            wrote on last edited by
            #5

            Hi friend, Maybe the problem is that, if you are using TCP/IP protocol, the structure is divided as multiple packets on the network, so you should first send the size of the structure (string + int), then use recv() and check that the number of bytes received are equal to the size of the structure before using the structure, or USE UDP/IP. something like this: int nRecv=0; while(nRecv //now i am sure i received the whole message, not just few packets //now use the structure Mohammad Gdeisat

            U 1 Reply Last reply
            0
            • M Mohammad A Gdeisat

              Hi friend, Maybe the problem is that, if you are using TCP/IP protocol, the structure is divided as multiple packets on the network, so you should first send the size of the structure (string + int), then use recv() and check that the number of bytes received are equal to the size of the structure before using the structure, or USE UDP/IP. something like this: int nRecv=0; while(nRecv //now i am sure i received the whole message, not just few packets //now use the structure Mohammad Gdeisat

              U Offline
              U Offline
              User 900278
              wrote on last edited by
              #6

              Hi Mohammad, Thanks for the help, I will try this option. Regards, Dinesh.

              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