Click here to Skip to main content
15,902,276 members
Home / Discussions / C#
   

C#

 
AnswerRe: Update Manager Pin
leppie20-Jun-08 7:05
leppie20-Jun-08 7:05 
QuestionHow can we remove specific node in the XML file by LINQ? Pin
Mohammad Dayyan20-Jun-08 6:58
Mohammad Dayyan20-Jun-08 6:58 
AnswerRe: How can we remove specific node in the XML file by LINQ? Pin
leppie20-Jun-08 7:02
leppie20-Jun-08 7:02 
GeneralRe: How can we remove specific node in the XML file by LINQ? Pin
Mohammad Dayyan20-Jun-08 7:20
Mohammad Dayyan20-Jun-08 7:20 
GeneralRe: How can we remove specific node in the XML file by LINQ? Pin
leppie20-Jun-08 8:05
leppie20-Jun-08 8:05 
GeneralRe: How can we remove specific node in the XML file by LINQ? Pin
Mohammad Dayyan20-Jun-08 9:09
Mohammad Dayyan20-Jun-08 9:09 
AnswerRe: How can we remove specific node in the XML file by LINQ? Pin
Mohammad Dayyan20-Jun-08 9:13
Mohammad Dayyan20-Jun-08 9:13 
QuestionPacket issues Pin
see_seA20-Jun-08 5:15
see_seA20-Jun-08 5:15 
I've highly modified the code found here http://www.codeproject.com/KB/IP/ChatAsynchTCPSockets.aspx.

When creating a packet, I give the following class the info it needs onto which is converts it into a byte[] and visa versa which can then be sent and received by a socket respectively.


public class Data
{
    //Default constructor
    public Command cmdCommand; //Command type (login, logout, send message, etcetera)
    public string strMessage; //Message text
    public string strName; //Name by which the client logs into the room

    public Data()
    {
        cmdCommand = Command.Null;
        strMessage = null;
        strName = null;
    }

    //Converts the bytes into an object of type Data
    public Data(byte[] data)
    {
        //The first four bytes are for the Command
        cmdCommand = (Command)BitConverter.ToInt32(data, 0);

        //The next four store the length of the name
        int nameLen = BitConverter.ToInt32(data, 4);

        //The next four store the length of the message
        int msgLen = BitConverter.ToInt32(data, 8);

        //This check makes sure that strName has been passed in the array of bytes
        if (nameLen > 0)
            strName = Encoding.UTF8.GetString(data, 12, nameLen);
        else
            strName = null;

        //This checks for a null message field
        if (msgLen > 0)
            strMessage = Encoding.UTF8.GetString(data, 12 + nameLen, msgLen);
        else
            strMessage = null;
    }

    //Converts the Data structure into an array of bytes
    public byte[] ToByte()
    {
        List<byte> result = new List<byte>();

        //First four are for the Command
        result.AddRange(BitConverter.GetBytes((int)cmdCommand));

        //Add the length of the name
        if (strName != null)
            result.AddRange(BitConverter.GetBytes(strName.Length));
        else
            result.AddRange(BitConverter.GetBytes(0));

        //Length of the message
        if (strMessage != null)
            result.AddRange(BitConverter.GetBytes(Encoding.UTF8.GetByteCount(strMessage)));
        else
            result.AddRange(BitConverter.GetBytes(0));

        //Add the name
        if (strName != null)
            result.AddRange(Encoding.UTF8.GetBytes(strName));

        //And, lastly we add the message text to our array of bytes
        if (strMessage != null)
            result.AddRange(Encoding.UTF8.GetBytes(strMessage));

        return result.ToArray();
    }
}</byte></byte>


However on some occasions of high traffic I get the following error:
Index and count must refer to a location within the buffer.
Parameter name: bytes
A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll


I feel the constructor which takes a byte array is the cause here. Can anyone suggest a better way of sending this data or point out the problem in the code which I cannot see? Sniff | :^) Help would be greatly appreciated.
AnswerRe: Packet issues Pin
leppie20-Jun-08 5:34
leppie20-Jun-08 5:34 
AnswerRe: Packet issues Pin
leppie20-Jun-08 5:37
leppie20-Jun-08 5:37 
GeneralRe: Packet issues Pin
see_seA20-Jun-08 5:52
see_seA20-Jun-08 5:52 
GeneralRe: Packet issues Pin
see_seA20-Jun-08 6:04
see_seA20-Jun-08 6:04 
GeneralRe: Packet issues Pin
leppie20-Jun-08 7:01
leppie20-Jun-08 7:01 
GeneralRe: Packet issues Pin
see_seA20-Jun-08 7:05
see_seA20-Jun-08 7:05 
GeneralRe: Packet issues Pin
see_seA20-Jun-08 7:56
see_seA20-Jun-08 7:56 
QuestionTransparency On Parent Form . Pin
unitecsoft20-Jun-08 4:58
unitecsoft20-Jun-08 4:58 
AnswerRe: Transparency On Parent Form . Pin
see_seA20-Jun-08 5:16
see_seA20-Jun-08 5:16 
Questioninserting data SQLCommand C# - am I missing something? Pin
laziale20-Jun-08 4:18
laziale20-Jun-08 4:18 
AnswerRe: inserting data SQLCommand C# - am I missing something? Pin
User 665820-Jun-08 4:25
User 665820-Jun-08 4:25 
GeneralRe: inserting data SQLCommand C# - am I missing something? Pin
laziale20-Jun-08 4:32
laziale20-Jun-08 4:32 
GeneralRe: inserting data SQLCommand C# - am I missing something? Pin
User 665820-Jun-08 4:36
User 665820-Jun-08 4:36 
GeneralRe: inserting data SQLCommand C# - am I missing something? Pin
laziale20-Jun-08 4:39
laziale20-Jun-08 4:39 
GeneralRe: inserting data SQLCommand C# - am I missing something? Pin
User 665820-Jun-08 4:39
User 665820-Jun-08 4:39 
GeneralRe: inserting data SQLCommand C# - am I missing something? Pin
laziale20-Jun-08 4:43
laziale20-Jun-08 4:43 
GeneralRe: inserting data SQLCommand C# - am I missing something? Pin
laziale20-Jun-08 5:01
laziale20-Jun-08 5:01 

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.