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. How can i sent structures through SOCKETS

How can i sent structures through SOCKETS

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminquestion
8 Posts 5 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.
  • S Offline
    S Offline
    swamy Narasimha
    wrote on last edited by
    #1

    Hi,i am trying to sent structures through SOCKETS,but the information is not reaching the server. I need source code to sent structures and delimit at server side

    Z C 2 Replies Last reply
    0
    • S swamy Narasimha

      Hi,i am trying to sent structures through SOCKETS,but the information is not reaching the server. I need source code to sent structures and delimit at server side

      Z Offline
      Z Offline
      zubair_ahmed
      wrote on last edited by
      #2

      Hope you would be sending commands in those structures. you can do like this. send this to client. struct SomeData { int command; int param1[100]; int param2[100]; } on client side read the sizeof(int) to get the command type the structure contains. once you know the command , you should read the 100 bytes for first param and then 100 for another param. This way your structure will be transmitted across wire. Hope this helps.

      Z.A

      S 1 Reply Last reply
      0
      • S swamy Narasimha

        Hi,i am trying to sent structures through SOCKETS,but the information is not reaching the server. I need source code to sent structures and delimit at server side

        C Offline
        C Offline
        Cedric Moonen
        wrote on last edited by
        #3

        Ca nyou post the code for the transmit receive that you have already ? I never worked with socket before but I suppose it works like any other 'communication' media. So for example if you are trying to pass the address of your structure, it will only transmit the address and not the content. Can you post your code to clarify the situation ?


        Cédric Moonen Software developer
        Charting control [Updated - v1.1]

        1 Reply Last reply
        0
        • Z zubair_ahmed

          Hope you would be sending commands in those structures. you can do like this. send this to client. struct SomeData { int command; int param1[100]; int param2[100]; } on client side read the sizeof(int) to get the command type the structure contains. once you know the command , you should read the 100 bytes for first param and then 100 for another param. This way your structure will be transmitted across wire. Hope this helps.

          Z.A

          S Offline
          S Offline
          swamy Narasimha
          wrote on last edited by
          #4

          Thankq Mr. zubair_ahmed, But i want 2 give clear idea abt the problem which i got. This is the data which i want 2 send: struct data { int id; CString str1; CString str2; }pt; UpdateData(); CString str; pt.str1=m_ID; pt.str2=m_Name; pt.id="A"; str.Format ("%d#%s#%s",pt); send(clientsock,str,str.GetLength(),0); Here Iam sending structure data tru string but.. is there any way to send data by structure address?? and How to get back the data at server side ...Thanks swamy

          M D 2 Replies Last reply
          0
          • S swamy Narasimha

            Thankq Mr. zubair_ahmed, But i want 2 give clear idea abt the problem which i got. This is the data which i want 2 send: struct data { int id; CString str1; CString str2; }pt; UpdateData(); CString str; pt.str1=m_ID; pt.str2=m_Name; pt.id="A"; str.Format ("%d#%s#%s",pt); send(clientsock,str,str.GetLength(),0); Here Iam sending structure data tru string but.. is there any way to send data by structure address?? and How to get back the data at server side ...Thanks swamy

            M Offline
            M Offline
            markkuk
            wrote on last edited by
            #5

            You can send structures that don't contain any pointers or structs/classes that contain pointers. A CString has a pointer to the actual string data, so you can't send the struct in your example code code directly over a socket.

            1 Reply Last reply
            0
            • S swamy Narasimha

              Thankq Mr. zubair_ahmed, But i want 2 give clear idea abt the problem which i got. This is the data which i want 2 send: struct data { int id; CString str1; CString str2; }pt; UpdateData(); CString str; pt.str1=m_ID; pt.str2=m_Name; pt.id="A"; str.Format ("%d#%s#%s",pt); send(clientsock,str,str.GetLength(),0); Here Iam sending structure data tru string but.. is there any way to send data by structure address?? and How to get back the data at server side ...Thanks swamy

              D Offline
              D Offline
              Divyang Mithaiwala
              wrote on last edited by
              #6

              Hello Narasimha,

              swamy Narasimha wrote:

              is there any way to send data by structure address?

              I think u have both client server on same PC. And u want to do Inter Process communication via socket. Isn't it?


              regards, Divyang Mithaiwala System Engineer & Software Engineer

              S 1 Reply Last reply
              0
              • D Divyang Mithaiwala

                Hello Narasimha,

                swamy Narasimha wrote:

                is there any way to send data by structure address?

                I think u have both client server on same PC. And u want to do Inter Process communication via socket. Isn't it?


                regards, Divyang Mithaiwala System Engineer & Software Engineer

                S Offline
                S Offline
                swamy Narasimha
                wrote on last edited by
                #7

                hi Divyang Mithaiwala, Iam sending data from one sys to another sys (two seperate systems) with IP and port.

                D 1 Reply Last reply
                0
                • S swamy Narasimha

                  hi Divyang Mithaiwala, Iam sending data from one sys to another sys (two seperate systems) with IP and port.

                  D Offline
                  D Offline
                  Divyang Mithaiwala
                  wrote on last edited by
                  #8

                  Hello swamy Narasimha, For that u have to type cast ur struct pointer to char pointer. But it is quit risky. Becoz as u know that differeint platform use different size for int datatype. And also change possion for date in struct to optimize best space. In both of this case ur data at other end is useless. And that's why some COM component provide fisrt field as sizeofstruct. To conform that both end use same style for data arrangment.


                  regards, Divyang Mithaiwala System Engineer & Software Engineer

                  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