Click here to Skip to main content
16,014,568 members
Home / Discussions / C#
   

C#

 
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 
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 
Ok I fixed it but still have a little problem:

Agent Log:
Sent notification to server that we were about to send 20230 bytes
Transferred the following actions to server: SERVICES,


Server Log:
[12/2/2010 9:48:56 AM]: -- 192.168.1.163:21064 has connected to the server 
[12/2/2010 9:48:56 AM]: 192.168.1.163:21064 is about to send 20230 bytes 
[12/2/2010 9:48:56 AM]: Finished receiving 8760 bytes from 192.168.1.163:21064 
[12/2/2010 9:48:56 AM]: Agent 192.168.1.163:21064 sent back null 
[12/2/2010 9:48:56 AM]: Finished sending 118 bytes to 192.168.1.163:21064 



So as you can see the agent is sending all the data, but the server is only getting 8760 bytes? Why is the server not reading all of the data?

State Object:
public Socket worker = null;
public int BufferSize = 4;
public byte[] buffer;
public MemoryStream ms = new MemoryStream();


Server:
int bytesRead = handler.EndReceive(iar);
                if (bytesRead > 0)
                {
                    if (state.BufferSize == 4)
                    {
                        state.BufferSize = BitConverter.ToInt32(state.buffer, 0);
                        state.buffer = new byte[state.BufferSize];

                        Logging.Log(handler.RemoteEndPoint.ToString() + " is about to send " + state.BufferSize.ToString() + " bytes", true);
                        handler.BeginReceive(state.buffer, 0, state.BufferSize, 0,
                            new AsyncCallback(ReadCallback), state);
                    }
                    else
                    {
                        state.ms.Write(state.buffer, 0, bytesRead);

                        Logging.Log("Finished receiving " + state.ms.Length.ToString() + " bytes from " +
                            handler.RemoteEndPoint.ToString(), true);

                        // All data has been received from client
                        state.ms.Seek(0, SeekOrigin.Begin);
                        IFormatter formatter = new BinaryFormatter();
                        object receivedObject = null;

                        try
                        {
                            receivedObject = formatter.Deserialize(state.ms);
                        }
                        catch (SerializationException se)
                        {
                            Logging.Log("Object passed was not capable of being deserialized. Error: " + se.ToString(), false);
                        }


Client:
MemoryStream ms = new MemoryStream();
                    IFormatter formatter = new BinaryFormatter();
                    formatter.Serialize(ms, commons);

                    // First send the length of data to server
                    byte[] buffer = ms.ToArray();
                    int len = buffer.Length;
                    s.Send(BitConverter.GetBytes(len));
                    Logging.Log("Sent notification to server that we were about to send " + len.ToString() + " bytes", true);

                    // Now send the actual data to server
                    s.Send(buffer);
                    Logging.Log("Transferred the following actions to server: "+ Tasks.GetActions(), true);

                    ms.Dispose();



I hope I took your suggestions and something like I should have.
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 
GeneralRe: Trying to deal with the memory leak in the Flash Player Pin
Luc Pattyn1-Dec-10 11:07
sitebuilderLuc Pattyn1-Dec-10 11:07 
GeneralRe: Trying to deal with the memory leak in the Flash Player Pin
DaveyM692-Dec-10 9:44
professionalDaveyM692-Dec-10 9:44 
AnswerRe: Trying to deal with the memory leak in the Flash Player Pin
Pete O'Hanlon1-Dec-10 9:12
mvePete O'Hanlon1-Dec-10 9:12 
AnswerRe: Trying to deal with the memory leak in the Flash Player Pin
Pete O'Hanlon1-Dec-10 22:47
mvePete O'Hanlon1-Dec-10 22:47 

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.