Click here to Skip to main content
16,020,249 members
Home / Discussions / C#
   

C#

 
QuestionC++ to C# Pin
t4ure4n6-Aug-06 11:22
t4ure4n6-Aug-06 11:22 
AnswerRe: C++ to C# Pin
Judah Gabriel Himango6-Aug-06 11:41
sponsorJudah Gabriel Himango6-Aug-06 11:41 
QuestionPaint a cell in DataGridView Pin
kalyanPaladugu6-Aug-06 10:56
kalyanPaladugu6-Aug-06 10:56 
AnswerRe: Paint a cell in DataGridView Pin
Judah Gabriel Himango6-Aug-06 11:38
sponsorJudah Gabriel Himango6-Aug-06 11:38 
GeneralRe: Paint a cell in DataGridView Pin
kalyanPaladugu6-Aug-06 13:06
kalyanPaladugu6-Aug-06 13:06 
GeneralRe: Paint a cell in DataGridView Pin
Judah Gabriel Himango6-Aug-06 15:56
sponsorJudah Gabriel Himango6-Aug-06 15:56 
GeneralRe: Paint a cell in DataGridView Pin
Erik Molenaar8-Aug-06 7:53
Erik Molenaar8-Aug-06 7:53 
QuestionSerialisation of more than one object Pin
Malcolm Smart6-Aug-06 10:00
Malcolm Smart6-Aug-06 10:00 
Hi
Sending objects over a wire from a client to a server. I 'serialise' the object on the client, send, via a Socket, and deserialise on server. Cool. Works a treat....for one object.

Whilst the server is handling the object I've sent, I might have sent three or four more, so when the server finally gets round to reading the socket stream again, it pulls in byte[] containing multiple serialised objects. Throwing that at my deserialise method fails. Do I have to manually tokensize the byte[] before sending and then on the server parse for the tokens? This could be a) slow as the tokens could be very large and b) not guarenteed, as the tokens I use could actually be part of the data in the serialised object, which would cause the deserialise to split in the wrong place.

Any ideas? Current code below

  public void Go()//lovely method name!
        {
            //now we want some asynchronous reading here....
            socket.BeginReceive(cs.RcvBuffer , 0 , cs.RcvBuffer.Length , SocketFlags.None , new AsyncCallback(ReadCallback), cs);
        }

        protected void ReadCallback(IAsyncResult ar)
        {
            clientState cs = (clientState)ar.AsyncState;

            try
            {
                int recvMsgSize = cs.ClntSock.EndReceive(ar);

                if (recvMsgSize > 0)
                {
                    cs.TotalBytes += recvMsgSize;

                    Console.WriteLine("Thread {0} - ReadCallback(): total received {1} bytes",
                        ID,
                        cs.TotalBytes);
                    //next line is good if array only has one object in but fails,
                    //which you'd expect if it has more...
                    SocketTest.MyTestClass m = Decode(cs.RcvBuffer);
                    DoSomethingWithMyTestClass( m );

                    Go();//read from stream again...is this the best way?
                }
            }
            catch(SocketException se)
            {
                Console.WriteLine(se.ErrorCode + ":" + se.Message);
            }
        }
    

        public SocketTest.MyTestClass Decode(byte[] theByteArray)
        {
            Console.WriteLine("Decoding {0} bytes", theByteArray.Length);
            MemoryStream ms = new MemoryStream(theByteArray);
            BinaryFormatter bf1 = new BinaryFormatter();
            ms.Position = 0;

            return (SocketTest.MyTestClass)bf1.Deserialize(ms);
        }



Regards

Malc
*********************************************


AnswerRe: Serialisation of more than one object Pin
Malcolm Smart6-Aug-06 10:39
Malcolm Smart6-Aug-06 10:39 
GeneralRe: Serialisation of more than one object Pin
HellfireHD6-Aug-06 11:32
HellfireHD6-Aug-06 11:32 
GeneralRe: Serialisation of more than one object Pin
Malcolm Smart6-Aug-06 20:58
Malcolm Smart6-Aug-06 20:58 
Questionjava stringtokenizer in c# Pin
Legolas_Bilbao6-Aug-06 9:56
Legolas_Bilbao6-Aug-06 9:56 
AnswerRe: java stringtokenizer in c# Pin
Colin Angus Mackay6-Aug-06 10:07
Colin Angus Mackay6-Aug-06 10:07 
GeneralRe: java stringtokenizer in c# Pin
Judah Gabriel Himango6-Aug-06 11:37
sponsorJudah Gabriel Himango6-Aug-06 11:37 
GeneralRe: java stringtokenizer in c# Pin
Legolas_Bilbao6-Aug-06 20:01
Legolas_Bilbao6-Aug-06 20:01 
Questionclass library and windows application trouble. Pin
digitalangel6-Aug-06 8:20
digitalangel6-Aug-06 8:20 
AnswerRe: class library and windows application trouble. Pin
Judah Gabriel Himango6-Aug-06 9:30
sponsorJudah Gabriel Himango6-Aug-06 9:30 
QuestionDataTable and DataGridView in C# -- Please Help Pin
kalyanPaladugu6-Aug-06 7:24
kalyanPaladugu6-Aug-06 7:24 
AnswerRe: DataTable and DataGridView in C# -- Please Help Pin
Judah Gabriel Himango6-Aug-06 9:32
sponsorJudah Gabriel Himango6-Aug-06 9:32 
GeneralRe: DataTable and DataGridView in C# -- Please Help Pin
kalyanPaladugu6-Aug-06 9:42
kalyanPaladugu6-Aug-06 9:42 
GeneralRe: DataTable and DataGridView in C# -- Please Help Pin
Judah Gabriel Himango6-Aug-06 11:34
sponsorJudah Gabriel Himango6-Aug-06 11:34 
QuestionHow can I alignment text On PRINTING ? ? ? Pin
galigal156-Aug-06 6:45
galigal156-Aug-06 6:45 
AnswerRe: How can I alignment text On PRINTING ? ? ? Pin
Rob Graham6-Aug-06 7:15
Rob Graham6-Aug-06 7:15 
QuestionInheritance in C# Pin
gns106-Aug-06 6:10
gns106-Aug-06 6:10 
AnswerRe: Inheritance in C# Pin
Ravi Bhavnani6-Aug-06 6:19
professionalRavi Bhavnani6-Aug-06 6:19 

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.