Click here to Skip to main content
15,887,417 members
Home / Discussions / C#
   

C#

 
QuestionGridview Pin
mjawadkhatri19-Aug-09 20:59
mjawadkhatri19-Aug-09 20:59 
AnswerRe: Gridview Pin
HimanshuJoshi19-Aug-09 21:04
HimanshuJoshi19-Aug-09 21:04 
AnswerRe: Gridview Pin
Vimalsoft(Pty) Ltd19-Aug-09 22:20
professionalVimalsoft(Pty) Ltd19-Aug-09 22:20 
AnswerRe: Gridview Pin
padmanabhan N19-Aug-09 22:43
padmanabhan N19-Aug-09 22:43 
AnswerRe: Gridview Pin
wyj12020-Aug-09 0:40
wyj12020-Aug-09 0:40 
QuestionNetworkStream problem... Pin
Trapper-Hell19-Aug-09 20:43
Trapper-Hell19-Aug-09 20:43 
AnswerRe: NetworkStream problem... Pin
Luc Pattyn19-Aug-09 22:51
sitebuilderLuc Pattyn19-Aug-09 22:51 
GeneralRe: NetworkStream problem... Pin
Trapper-Hell23-Aug-09 21:07
Trapper-Hell23-Aug-09 21:07 
As requested, I will attempt to answer all the questions provided so that I may be provided with an answer which will solve this problem...


Luc Pattyn wrote:
- information on how both PCs are connected


Physically the PCs are on a LAN, thus the network speed should be of no problem. There are multiple connections established in C#, all in TCP/IP. There are about three open ports on each side, each with a separate network stream for separate purposes. However, the exception only occurs in one of these.


Luc Pattyn wrote:
- information on the data written each time: is it text? binary data? how much? what does it represent?


The data transferred in this particular NetworkStream is binary data representing a serialized Bitmap instance. Whilst the length of the serialized Bitmap instance varies every time, it is around ~710500 bytes long...


Luc Pattyn wrote:
- the entire code of the method that writes the data, and its context (which thread, how is it triggered, etc)


The method called is Send(object) which looks as follows:

public bool Send(object oSend)
        {
            try
            {
                SendString(Serialize(oSend).Length.ToString());
                return SendBytes(Serialize(oSend));
            }
            catch
            {
                return false;
            }
        }


Serialize is as follows:

public byte[] Serialize(object oSerialize)
        {
            if (oSerialize != null)
            {
                lock (serializeLock)
                {
                    msMem = new MemoryStream();
                    bf = new BinaryFormatter();

                    try
                    {
                        bf.Serialize(msMem, oSerialize);
                        msMem.Flush();
                        msMem.Position = 0;

                        oSerialize = null;
                        bf = null;
                        return msMem.ToArray();
                    }
                    catch
                    {
                        return null;
                    }
                }
            }
            else
                return null;
        }


SendString:


public bool SendString(string strSend)
        {
            try
            {
                SendBytes(new System.Text.ASCIIEncoding().GetBytes(strSend));
                return true;
            }
            catch
            {
                return false;
            }
        }


and finally, SendBytes:

public bool SendBytes(byte[] bUp)
        {
            if (bUp != null && nsStream != null)
            {
                lock (sendLock)
                {
                    try
                    {
                        if (nsStream.CanWrite)
                            nsStream.Write(bUp, 0, bUp.Length);

                        nsStream.Flush();

                        int x = 0;

                        while (nsStream.DataAvailable && x < dataReadWait)
                        {
                            x++;
                            // Wait for data to be read
                        }

                        return true;
                    }
                    catch
                    {
                        return false;
                    }
                }
            }
            else
                return false;
        }



On the Receiving end,

Receive:

public object Receive()
        {
            return Deserialize(ReceiveBytes());
        }


ReceiveBytes:

public byte[] ReceiveBytes()
        {
            bDown = new byte[8];

            try
            {
                int bytesLength = Convert.ToInt32(ReceiveString(8));
                bDown = new byte[bytesLength];

                return ReceiveBytes(bytesLength);
            }
            catch
            {
                return null;
            }
        }


public byte[] ReceiveBytes(int length)
        {
            if (nsStream != null)
            {
                lock (receiveLock)
                {
                    bDown = new byte[length];

                    try
                    {
                        if (nsStream.CanRead)
                            nsStream.Read(bDown, 0, bDown.Length);

                        nsStream.Flush();
                        return bDown;
                    }
                    catch
                    {
                        return null;
                    }
                }
            }
            else
                return null;
        }


public object Deserialize(byte[] oDeserialize)
        {
            if (oDeserialize != null && oDeserialize.Length != 0)
            {
                lock (deserializeLock)
                {
                    msMem = new MemoryStream(oDeserialize);
                    bf = new BinaryFormatter();
                    msMem.Position = 0;

                    try
                    {
                        obj = bf.Deserialize(msMem);
                        bf = null;
                        msMem = null;
                        return obj;
                    }
                    catch
                    {
                        msMem = null;
                        bf = null;
                        obj = null;
                        return null;
                    }
                }
            }
            else
                return null;
        }


I am sorry for taking so much space for the code, but I have did as requested. I hope you can help me with this issue!
GeneralRe: NetworkStream problem... Pin
Luc Pattyn24-Aug-09 0:38
sitebuilderLuc Pattyn24-Aug-09 0:38 
GeneralRe: NetworkStream problem... Pin
Trapper-Hell24-Aug-09 2:30
Trapper-Hell24-Aug-09 2:30 
GeneralRe: NetworkStream problem... Pin
Luc Pattyn24-Aug-09 2:36
sitebuilderLuc Pattyn24-Aug-09 2:36 
GeneralRe: NetworkStream problem... Pin
Trapper-Hell24-Aug-09 20:06
Trapper-Hell24-Aug-09 20:06 
GeneralRe: NetworkStream problem... Pin
Luc Pattyn24-Aug-09 23:49
sitebuilderLuc Pattyn24-Aug-09 23:49 
QuestionWin Form - resize form problem Pin
Gindi Bar Yahav19-Aug-09 19:41
Gindi Bar Yahav19-Aug-09 19:41 
AnswerRe: Win Form - resize form problem Pin
dan!sh 19-Aug-09 20:14
professional dan!sh 19-Aug-09 20:14 
AnswerRe: Win Form - resize form problem Pin
darkelv19-Aug-09 20:15
darkelv19-Aug-09 20:15 
GeneralRe: Win Form - resize form problem Pin
Gindi Bar Yahav19-Aug-09 20:30
Gindi Bar Yahav19-Aug-09 20:30 
GeneralRe: Win Form - resize form problem Pin
dan!sh 19-Aug-09 20:42
professional dan!sh 19-Aug-09 20:42 
GeneralRe: Win Form - resize form problem Pin
darkelv19-Aug-09 21:37
darkelv19-Aug-09 21:37 
AnswerRe: Win Form - resize form problem Pin
Trapper-Hell19-Aug-09 20:49
Trapper-Hell19-Aug-09 20:49 
QuestionResource File Help Pin
Dushan12319-Aug-09 18:12
Dushan12319-Aug-09 18:12 
AnswerRe: Resource File Help Pin
Christian Graus19-Aug-09 18:23
protectorChristian Graus19-Aug-09 18:23 
Questionusing DOM how to identify the link that is clicked? Pin
Jacobb Michael19-Aug-09 17:54
Jacobb Michael19-Aug-09 17:54 
QuestionHealth monitoring server up or down and logging to database Pin
ramindya19-Aug-09 13:37
ramindya19-Aug-09 13:37 
AnswerRe: Health monitoring server up or down and logging to database Pin
Christian Graus19-Aug-09 15:36
protectorChristian Graus19-Aug-09 15:36 

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.