Click here to Skip to main content
15,884,298 members
Home / Discussions / C#
   

C#

 
GeneralRe: Hide database file from user Pin
NarendraSinghJTV19-Dec-09 0:23
NarendraSinghJTV19-Dec-09 0:23 
QuestionHow to Find the documentation oF MSPastry Library in MSDN? Pin
ksaw12318-Dec-09 0:24
ksaw12318-Dec-09 0:24 
AnswerRe: How to Find the documentation oF MSPastry Library in MSDN? Pin
Dave Kreskowiak18-Dec-09 4:10
mveDave Kreskowiak18-Dec-09 4:10 
QuestionThreading Question Pin
Harvey Saayman17-Dec-09 23:11
Harvey Saayman17-Dec-09 23:11 
AnswerRe: Threading Question Pin
#realJSOP17-Dec-09 23:40
mve#realJSOP17-Dec-09 23:40 
GeneralRe: Threading Question Pin
Harvey Saayman18-Dec-09 0:24
Harvey Saayman18-Dec-09 0:24 
AnswerRe: Threading Question Pin
Pete O'Hanlon18-Dec-09 0:14
mvePete O'Hanlon18-Dec-09 0:14 
GeneralRe: Threading Question Pin
Harvey Saayman18-Dec-09 2:32
Harvey Saayman18-Dec-09 2:32 
Hey Pete, long time since we've spoken Smile | :)

Pete O'Hanlon wrote:
We use it to hive off our Tcp processing, and it just works


So you've done this before?

Here's my PacketReceivedCallback:

private void PacketReceivedCallback(IAsyncResult result)
{
    IOClient client = (IOClient)result.AsyncState;

    int bytesRead = client.Socket.EndReceive(result);

    if (bytesRead != 0)
    {
        lock (clientLock)
        {
            StringBuilder sb = new StringBuilder();

            if (client.IncompleatePacket.Length > 0)
            {
                sb = client.IncompleatePacket;
            }

            foreach (byte CurrentByte in client.ReadBuffer)
            {
                if (CurrentByte == EmptyByte)
                {
                    continue;
                }

                if (CurrentByte == PacketTerminator)
                {
                    PacketReceived(client, sb.ToString());
                    bytesReceived += sb.ToString().Length;

                    BroadcastPacket(sb.ToString(), client);

                    sb = new StringBuilder();
                    client.IncompleatePacket = new StringBuilder();
                }

                if (CurrentByte != EmptyByte && CurrentByte != PacketTerminator)
                {
                    sb.Append((char)CurrentByte);
                }
            }

            if (sb.Length > 0)
            {
                client.IncompleatePacket.Append(sb.ToString());
            }
        }
        client.Socket.BeginReceive(client.ReadBuffer, 0, client.ReadBuffer.Length, SocketFlags.None, 
                                   new AsyncCallback(PacketReceivedCallback), client);
    }
    else
    {
        CloseConnection(client);
    }
}


The way I see it is I'll have a collection, possibly a List<string>, in my IOClient class. Instead of trying to split the packets up in the callback I'll call MyStringList.Add(Encoding.ASCII.GetString(client.ReadBuffer,0,bytesRead));

Then my SmartThreadPool will sit and take a piece of data from that list and strip out the individual packets more or less like I'm doing in the above snippet... Is that more or less how its done?

And then would you mind telling me how I make the smart thread pool do this in the most effiecient manner? Like i told JSOP, I've used SmartThreadPool before, but not quite like this...

Thanks bud Smile | :)

Harvey Saayman - South Africa
Software Developer
.Net, C#, SQL

you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

GeneralRe: Threading Question Pin
Luc Pattyn18-Dec-09 5:23
sitebuilderLuc Pattyn18-Dec-09 5:23 
GeneralRe: Threading Question Pin
Harvey Saayman18-Dec-09 5:56
Harvey Saayman18-Dec-09 5:56 
GeneralRe: Threading Question Pin
Luc Pattyn18-Dec-09 6:19
sitebuilderLuc Pattyn18-Dec-09 6:19 
GeneralRe: Threading Question Pin
Harvey Saayman18-Dec-09 7:49
Harvey Saayman18-Dec-09 7:49 
Question[Message Deleted] Pin
thungphan17-Dec-09 20:53
thungphan17-Dec-09 20:53 
AnswerMessage Closed Pin
17-Dec-09 21:25
stancrm17-Dec-09 21:25 
GeneralRe: convert int to byte array using shift operator Pin
thungphan17-Dec-09 21:42
thungphan17-Dec-09 21:42 
AnswerRe: convert int to byte array using shift operator Pin
harold aptroot17-Dec-09 21:52
harold aptroot17-Dec-09 21:52 
QuestionRuntime ToFront toBack? Pin
dennis_max2717-Dec-09 20:29
dennis_max2717-Dec-09 20:29 
AnswerRe: Runtime ToFront toBack? Pin
Saksida Bojan17-Dec-09 20:37
Saksida Bojan17-Dec-09 20:37 
GeneralRe: Runtime ToFront toBack? Pin
dennis_max2717-Dec-09 20:47
dennis_max2717-Dec-09 20:47 
GeneralRe: Runtime ToFront toBack? Pin
Saksida Bojan17-Dec-09 20:50
Saksida Bojan17-Dec-09 20:50 
GeneralRe: Runtime ToFront toBack? Pin
dennis_max2717-Dec-09 20:54
dennis_max2717-Dec-09 20:54 
GeneralRe: Runtime ToFront toBack? Pin
Saksida Bojan17-Dec-09 21:00
Saksida Bojan17-Dec-09 21:00 
GeneralRe: Runtime ToFront toBack? Pin
dennis_max2717-Dec-09 21:00
dennis_max2717-Dec-09 21:00 
AnswerRe: Runtime ToFront toBack? Pin
dennis_max273-Jan-10 22:37
dennis_max273-Jan-10 22:37 
Questionparsing javascript in realtime Pin
Haim Nachum17-Dec-09 19:39
Haim Nachum17-Dec-09 19:39 

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.