P
puzzlecracker
Problem:
An Application server send messages to the client (and I am
developing the client) based on the client request:
client [Do something]=====================================>server
client <============== [response with message in the
buffer[1024]] server
client <============== [response with message in the
buffer[1024]] server
client [Do something]=====================================>server
client [Do something]=====================================>server
client <============== [response with message in the
buffer[1024]] server
As you can see, server doesn't have to send just one message back,
though all messages are equal in size.
So what I am trying to do is to create a separate thread that will
always listen to the responses from the server and then delegate the
response to appropriate handler. However, I don't want thread to
constantly run in the while(true) but only be awaken when a response
actually arrives. Here is my thread function thus far:
private void ThreadReceiverProc()
{
while (IsTermnaeteReceiver = false)
{
lock (connLock)
{
try
{
client.BeginReceive(buffer, 0,
StateObject.BufferSize, 0,
new AsyncCallback(ReceiveCallback), state);
receiveDone.WaitOne()
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
}
Is this correct approach from the design and efficiency point of view?
I would all the tips, for I am a noob to csharp
Thanks
An Application server send messages to the client (and I am
developing the client) based on the client request:
client [Do something]=====================================>server
client <============== [response with message in the
buffer[1024]] server
client <============== [response with message in the
buffer[1024]] server
client [Do something]=====================================>server
client [Do something]=====================================>server
client <============== [response with message in the
buffer[1024]] server
As you can see, server doesn't have to send just one message back,
though all messages are equal in size.
So what I am trying to do is to create a separate thread that will
always listen to the responses from the server and then delegate the
response to appropriate handler. However, I don't want thread to
constantly run in the while(true) but only be awaken when a response
actually arrives. Here is my thread function thus far:
private void ThreadReceiverProc()
{
while (IsTermnaeteReceiver = false)
{
lock (connLock)
{
try
{
client.BeginReceive(buffer, 0,
StateObject.BufferSize, 0,
new AsyncCallback(ReceiveCallback), state);
receiveDone.WaitOne()
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
}
Is this correct approach from the design and efficiency point of view?
I would all the tips, for I am a noob to csharp
Thanks