I have a socket-communication thread based on C#. The buffer in the server is 1024 bytes, now I need a way to transfer the data between the communication thread & the main thread. How can I do this? Do I need to open a new buffer, then copy the data to it? Or can I just get the data from the buffer of the client or the server?
private void ServerResponse()
{
byte[] buff = new byte[1024];
string msg;
int len;
try
{
if (!Stream.CanRead)
{
return;
}
stopFlag = false;
while (!stopFlag)
{
len = Stream.Read(buff, 0, buff.Length);
if (len < 1
{
Thread.Sleep(200);
continue;
}
}
}
}
The above is the function that the server uses to get the data from the client. My question is could I send the data which this function gets to the main thread, or I should set a new buffer outside the definition of the function above and copy the data to it.