Serialization/Deserialization Using Sockets
-
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!
-
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!
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
-
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
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?
-
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?
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
-
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
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?
-
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?
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
-
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
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)...
-
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)...
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