Receive data from client

Hello experts,

I am a server waiting for the client and receivng the data from the client periodically.When I receive the data ,I have to make some calculations on the data received and I have to paint the form accordingly.I am working in VC++ .NET.
I will be receiving the data from the client for every 10 seconds of time.I want my program to wait at the receive function till it recives the data and then paint periodically.

I made the socket non blocking but I am not able to achieve what I wanted.

Here is the sample of code......

do
{
iResult = recv(s,buffer,256,0);//I want the function to wait here till it receives the data from client for every iteration.
//do some paint opertion here.....
}wjile(iResult!=-1);

tatikor_143Asked:
Who is Participating?
 
Kent OlsenData Warehouse Architect / DBACommented:

You shouldn't be blocking from the main thread.

Create another thread and let it handle the connection(s).  When the thread receives data, it should single thread through the main thread to perform the screen updates and paints.

0
 
Kent OlsenData Warehouse Architect / DBACommented:

Perhaps I don't understand.  If the client is sending data every 10 seconds, just define the server socket as blocking.


Kent
0
 
tatikor_143Author Commented:
If I make the socket as blocking then I will not be able to perform the paint operations but I am sure that I will be receiving the data.
0
 
tatikor_143Author Commented:
Hi kent,

I inserted the code in a button handler......
When I click the button,it starts receiving the data from the client and paints on the form......
If I create  a thread for receiving the data then How can I suynchronise the paint operation ?
any idea.....
0
 
tatikor_143Author Commented:
I am still in a confusion wether I have to look towards the socket side or towartds the .NET side....

I dont know Wether I am going in a right way.....
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.