Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Im writing socket appliction,where server is sending data for every two seconds.

At client side it is a SDI application where the data received need to be plotted as graph.

so Im receiving data at CSockEt_Client::OnReceive()

But how can i reflect on CClientView::OnDraw(CDC *pDC)
to Plot Graph..?
At Server
C++
while(1)
		{
			for(int i=0;i<col;i++)
			{
						Sleep(2000);
				
					fdata.w1=a[i][0];
					fdata.w2=a[i][1];
					fdata.w3=a[i][2];
					fdata.w4=a[i][3];
					                                  m_server.m_client.Send(&fdata,sizeof(fdata));

			}


At Client side
C++
void CClient_Socket::OnReceive(int nErrorCode) 
{	filedata fdata;
	
		int br=Receive(&fdata,sizeof(fdata));
                w[0]=fdata.w1;
		w[1]=fdata.w2;
		w[2]=fdata.w3;
		w[3]=fdata.w4;
CSocket::OnReceive(nErrorCode);
}


C++
void CClient_graphView::OnDraw(CDC* dc)
{
	CClient_graphDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	m_Graph->DrawGraph(dc);							          							     m_Graph->AddPoint(dc, w[0]);
}


so in what way i need to declare int w[i]... either static,extern...?

please help me out..

Thanks in advance..
Posted
Updated 5-Dec-12 0:53am
v3

 
Share this answer
 
In a SDI application the document class should hold all your data, so the points of the graph will be stored there, probably as some sort of class variable (array, list, vector etc). Then in your drawing code you use that data to draw the part of your picture that fits the visible portion of your window (allowing for scrolling etc.). The call to CDocument::UpdateAllViews() ensures that your window is repainted after the document's contents have been modified.
 
Share this answer
 
Comments
hiiakiia 5-Dec-12 23:57pm    
Thank u for ur reply..
I tried it.. Declared a array in Doc Class using Document object i accessed that array.. in OnDraw i called UpdateAllViews (NULL);
But there is no change it is not reflecting the array changes that are being done on
Onreceive()
Here is sample bit of code:
d_var is Doc class object;
m_Graph->DrawGraph(dc);
m_Graph->AddPoint(dc, d_var.m_GValue[i]);
d_var.UpdateAllViews(NULL);

at OnReceive()

d_var.m_GValue[0]=fdata.w1;
d_var.m_GValue[1]=fdata.w2;
d_var.m_GValue[2]=fdata.w3;
d_var.m_GValue[3]fdata.w4;

can u give sample code as example ..
Richard MacCutchan 6-Dec-12 3:15am    
You are only saving four points, and then overwriting them on the next receive. You need to save all the points that you receive; remember, every time OnDraw() is called it redraws the entire window.
hiiakiia 6-Dec-12 3:55am    
Those four are values for four different graphs.. for each 2 sec a value is received from server and it need to be added to the previous.. so now i need to add each point and need to draw the graph...
is it right...!
will UpdateAllViews (NULL) will call OnDraw function again and again..?
hiiakiia 6-Dec-12 8:01am    
Thank U Mr.Richard .. I Got the graph..
But after few sec it is crashing ...!

while debugging im unable to trace the reason .. is there other way to trace it...
Richard MacCutchan 6-Dec-12 8:42am    
Without knowing what the code is doing or where the crash occurs it is impossible to make any guesses. You could try adding some simple debug statements and see how far it gets before crashing.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900