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#
  4. Serialization/Deserialization Using Sockets

Serialization/Deserialization Using Sockets

Scheduled Pinned Locked Moved C#
comjsonquestionannouncement
8 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.
  • D Offline
    D Offline
    dwebster
    wrote on last edited by
    #1

    I have two programs, A and B... program A serializes some data into a buffer, attaches via a socket connection to program B, transmits the serialized data via socket to program B, program B then deserializes the data and all is fine. This process works great if programs A and B communicate on the same machine using the following code to obtain the IP Address: m_ipHostInfo = Dns.Resolve(Dns.GetHostName()); However, if you obtain the IP Address in this manner: m_ipHostInfo = Dns.Resolve("www.anyplace.com"); ... the deserialization fails in program B, complaining about an invalid header or object version difference... The data is indeed making it from program A to program B by resolving the DNS for the domain, it just seems like it is getting corrupted in some way. Any suggestions? Thanks!

    D 1 Reply Last reply
    0
    • D dwebster

      I have two programs, A and B... program A serializes some data into a buffer, attaches via a socket connection to program B, transmits the serialized data via socket to program B, program B then deserializes the data and all is fine. This process works great if programs A and B communicate on the same machine using the following code to obtain the IP Address: m_ipHostInfo = Dns.Resolve(Dns.GetHostName()); However, if you obtain the IP Address in this manner: m_ipHostInfo = Dns.Resolve("www.anyplace.com"); ... the deserialization fails in program B, complaining about an invalid header or object version difference... The data is indeed making it from program A to program B by resolving the DNS for the domain, it just seems like it is getting corrupted in some way. Any suggestions? Thanks!

      D Offline
      D Offline
      David Stone
      wrote on last edited by
      #2

      Are you using network streams to transmit the serialized class? Could you serialize it to a file and then send the file across and then do a check on the file to see if it is the same? David Stone It seemed similar to someone saying, "Would you like to meet my knife collection?" Ryan Johnston on Elaine's sig

      D 1 Reply Last reply
      0
      • D David Stone

        Are you using network streams to transmit the serialized class? Could you serialize it to a file and then send the file across and then do a check on the file to see if it is the same? David Stone It seemed similar to someone saying, "Would you like to meet my knife collection?" Ryan Johnston on Elaine's sig

        D Offline
        D Offline
        dwebster
        wrote on last edited by
        #3

        I am using async sockets: private void SendBinary(Socket sock, byte[] buffer) { sock.BeginSend(buffer, 0, buffer.Length, 0, new AsyncCallback(SendBufferCallback), sock); } private void SendBufferCallback(IAsyncResult ar) { Socket sock = (Socket)ar.AsyncState; int nBytes = sock.EndSend(ar); sendDone.Set(); } I can try to serialize it to a file on the send and receive sides and see what the differences are... if I find differences (which I should), then what do you think the problem is?

        D 1 Reply Last reply
        0
        • D dwebster

          I am using async sockets: private void SendBinary(Socket sock, byte[] buffer) { sock.BeginSend(buffer, 0, buffer.Length, 0, new AsyncCallback(SendBufferCallback), sock); } private void SendBufferCallback(IAsyncResult ar) { Socket sock = (Socket)ar.AsyncState; int nBytes = sock.EndSend(ar); sendDone.Set(); } I can try to serialize it to a file on the send and receive sides and see what the differences are... if I find differences (which I should), then what do you think the problem is?

          D Offline
          D Offline
          David Stone
          wrote on last edited by
          #4

          Why do you think you will find differences. It's just copying the byte stream across the sockets. Thus it should be just the same, right? David Stone It seemed similar to someone saying, "Would you like to meet my knife collection?" Ryan Johnston on Elaine's sig

          D 1 Reply Last reply
          0
          • D David Stone

            Why do you think you will find differences. It's just copying the byte stream across the sockets. Thus it should be just the same, right? David Stone It seemed similar to someone saying, "Would you like to meet my knife collection?" Ryan Johnston on Elaine's sig

            D Offline
            D Offline
            dwebster
            wrote on last edited by
            #5

            I added code to write out a file of the buffer prior to sending from the client. I also wrote out a file of the buffer received on the host/server via the socket connection. The buffer on the host is larger than the client buffer. I am investigating the differences now... any clues?

            D 1 Reply Last reply
            0
            • D dwebster

              I added code to write out a file of the buffer prior to sending from the client. I also wrote out a file of the buffer received on the host/server via the socket connection. The buffer on the host is larger than the client buffer. I am investigating the differences now... any clues?

              D Offline
              D Offline
              David Stone
              wrote on last edited by
              #6

              dwebster wrote: The buffer on the host is larger than the client buffer. That's the problem. If you have a bigger buffer transmitting to a smaller buffer then some of the first buffer will get chopped off. That is probably why you can't deserialize the class; it's not whole and intact when you try to deserialize it. Can you increase the buffer size on the client? David Stone It seemed similar to someone saying, "Would you like to meet my knife collection?" Ryan Johnston on Elaine's sig

              D 1 Reply Last reply
              0
              • D David Stone

                dwebster wrote: The buffer on the host is larger than the client buffer. That's the problem. If you have a bigger buffer transmitting to a smaller buffer then some of the first buffer will get chopped off. That is probably why you can't deserialize the class; it's not whole and intact when you try to deserialize it. Can you increase the buffer size on the client? David Stone It seemed similar to someone saying, "Would you like to meet my knife collection?" Ryan Johnston on Elaine's sig

                D Offline
                D Offline
                dwebster
                wrote on last edited by
                #7

                Actually... Program A (the client) is sending to program B (the host/server) and program B (the host/server) winds up having a larger buffer than program A (the client). Also, remember that the buffers are just fine when using Dns.GetHostName() rather than www.anywhere.com to obtain the IP Address... there is some difference in sending the buffer via sockets to the localhost versus sending the buffer via sockets through the internet (using DNS to resolve)...

                D 1 Reply Last reply
                0
                • D dwebster

                  Actually... Program A (the client) is sending to program B (the host/server) and program B (the host/server) winds up having a larger buffer than program A (the client). Also, remember that the buffers are just fine when using Dns.GetHostName() rather than www.anywhere.com to obtain the IP Address... there is some difference in sending the buffer via sockets to the localhost versus sending the buffer via sockets through the internet (using DNS to resolve)...

                  D Offline
                  D Offline
                  David Stone
                  wrote on last edited by
                  #8

                  Okay. Scrap the buffer theory. Can you look at the actual data that the program is sending over. If you write it to a binary file, then VS.NET can read it... If there is just "extra" information in the hosts copy of the class, then you could just trim the buffer... David Stone It seemed similar to someone saying, "Would you like to meet my knife collection?" Ryan Johnston on Elaine's sig

                  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