Click here to Skip to main content
15,919,121 members
Home / Discussions / C#
   

C#

 
QuestionCan not deserialize [modified] Pin
Jacob D Dixon1-Dec-10 11:39
Jacob D Dixon1-Dec-10 11:39 
AnswerRe: Can not deserialize Pin
jschell1-Dec-10 12:16
jschell1-Dec-10 12:16 
AnswerRe: Can not deserialize Pin
Luc Pattyn1-Dec-10 12:17
sitebuilderLuc Pattyn1-Dec-10 12:17 
GeneralRe: Can not deserialize Pin
Jacob D Dixon1-Dec-10 12:30
Jacob D Dixon1-Dec-10 12:30 
AnswerRe: Can not deserialize Pin
Luc Pattyn1-Dec-10 13:06
sitebuilderLuc Pattyn1-Dec-10 13:06 
GeneralRe: Can not deserialize Pin
Jacob D Dixon1-Dec-10 14:48
Jacob D Dixon1-Dec-10 14:48 
AnswerRe: Can not deserialize Pin
Luc Pattyn1-Dec-10 15:02
sitebuilderLuc Pattyn1-Dec-10 15:02 
GeneralRe: Can not deserialize Pin
Jacob D Dixon1-Dec-10 16:21
Jacob D Dixon1-Dec-10 16:21 
Luc,

Thank you for the replies. So I do understand how to send the bytes that contain the length of how many bytes are in my custom object. What I am trying to understand is how I will work this into my program.
How will I know to try to deserialize or just convert the bytes to integer?

On the server the first receive would always be the integer. Once I received all that data I would then call another method to perform another receive but this time deserializing it?

Example:
private void FirstReadCallback(IAsyncResult iar)
{
      StateObject so = iar as StateObject;
      Socket handler = so.workSocket;    
 
            int bytesRead = handler.EndReceive(iar);
            if (bytesRead > 0)
            {
                  int myLength = BitConverter.ToInt32(state.buffer);
                  state.buffer = new byte[myLength];
                  
                  // Now receive the serialized data
                  handler.BeginReceive(state.buffer, 0, state.buffer.Length, 0, new AsyncCallback(SecondReadCallback), state);
            }
}

private void SecondReadCallback(IAsyncResult iar)
{
    StateObject state = iar.AsyncState as StateObject;
    Socket handler = state.worker;
  
        int bytesRead = handler.EndReceive(iar);
        if (bytesRead > 0)
        {
             state.ms.Write(state.buffer, 0, bytesRead);
             state.ms.Seek(0, SeekOrigin.Begin);
 
             IFormatter formatter = new BinaryFormatter();
             object receivedObject = null;
 
             receivedObject = formatter.Deserialize(state.ms);

             // and so on
        }
}

GeneralRe: Can not deserialize Pin
Luc Pattyn1-Dec-10 16:46
sitebuilderLuc Pattyn1-Dec-10 16:46 
GeneralRe: Can not deserialize [modified] Pin
Jacob D Dixon1-Dec-10 17:11
Jacob D Dixon1-Dec-10 17:11 
GeneralRe: Can not deserialize Pin
Luc Pattyn1-Dec-10 22:22
sitebuilderLuc Pattyn1-Dec-10 22:22 
GeneralRe: Can not deserialize Pin
Jacob D Dixon2-Dec-10 4:57
Jacob D Dixon2-Dec-10 4:57 
AnswerRe: Can not deserialize Pin
Luc Pattyn2-Dec-10 5:19
sitebuilderLuc Pattyn2-Dec-10 5:19 
GeneralRe: Can not deserialize Pin
Jacob D Dixon2-Dec-10 6:09
Jacob D Dixon2-Dec-10 6:09 
GeneralRe: Can not deserialize Pin
Luc Pattyn2-Dec-10 6:30
sitebuilderLuc Pattyn2-Dec-10 6:30 
GeneralRe: Can not deserialize Pin
Jacob D Dixon2-Dec-10 7:56
Jacob D Dixon2-Dec-10 7:56 
GeneralRe: Can not deserialize Pin
Luc Pattyn2-Dec-10 8:20
sitebuilderLuc Pattyn2-Dec-10 8:20 
QuestionTrying to deal with the memory leak in the Flash Player Pin
jbradshaw1-Dec-10 6:09
jbradshaw1-Dec-10 6:09 
AnswerRe: Trying to deal with the memory leak in the Flash Player Pin
Luc Pattyn1-Dec-10 6:52
sitebuilderLuc Pattyn1-Dec-10 6:52 
GeneralRe: Trying to deal with the memory leak in the Flash Player Pin
jbradshaw1-Dec-10 7:27
jbradshaw1-Dec-10 7:27 
QuestionRe: Trying to deal with the memory leak in the Flash Player Pin
jbradshaw1-Dec-10 7:32
jbradshaw1-Dec-10 7:32 
AnswerRe: Trying to deal with the memory leak in the Flash Player Pin
Luc Pattyn1-Dec-10 7:42
sitebuilderLuc Pattyn1-Dec-10 7:42 
GeneralRe: Trying to deal with the memory leak in the Flash Player Pin
Pete O'Hanlon1-Dec-10 9:39
mvePete O'Hanlon1-Dec-10 9:39 
GeneralRe: Trying to deal with the memory leak in the Flash Player Pin
Luc Pattyn1-Dec-10 10:09
sitebuilderLuc Pattyn1-Dec-10 10:09 
GeneralRe: Trying to deal with the memory leak in the Flash Player Pin
Pete O'Hanlon1-Dec-10 10:23
mvePete O'Hanlon1-Dec-10 10:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.