Click to See Complete Forum and Search --> : Another MFC socket programming problem


shahin
February 3rd, 2005, 04:27 PM
First of all I like to thank everyone here for their help in last thread. My new question is this:

I have a client and server application. I run the client on my laptop and server in desktop. It is simply sending some data from server to client.

This is how I do my send:
pNBaseD->OutputToSocket( pDoc->NetOptionCurrent, pDoc->StaInfo, pDoc->PredStaInfoCurrent, pDoc->MeaAllRaw, m_NetCorr_iPRNArray, m_NetCorr_psNetCorr, m_NetCorr_psPredNetCorr, pDoc->EpochTime, m_pServerSock, &m_cControlMessage );

which will call send at the end.

Problem:

If I put a breakpoint in my client at recive function in debuging mode and make it hang there, my server tries to send data to client. after while , my server hangs in the send and send will never returns.

My guess: ( Please tell me if it is right)
the internal buffer that server writes the data gets full since the client is not reciving. so that is why the send does not return.

Solution:

Is there a function on MFC that I can call to check this internal buffer and if it is full then do not try to write to it and skip the send???

I apperitiate any help you guys can give me, I am new to MFC, even if you can direct me to article that I can read, that would be great.

shahin
February 10th, 2005, 02:52 PM
No one is able to help with this Question???!!! :( :(

miteshpandey
February 11th, 2005, 10:58 AM
Please provide code around the send(...) and recv(...) functions.

miteshpandey
February 11th, 2005, 11:00 AM
Sorry for the previoius reply coz u are using MFC.

Are you using CSocekts.

Please do provide some code

shahin
February 14th, 2005, 11:06 AM
yes,, sorry, I did not check this, I sort of gave up on this. This is pice of code around the send:

unsigned int CClientSock::Write( const unsigned char* Buffer, const unsigned long numBytes, const unsigned short TxID, const unsigned int timesToIssue,
const unsigned int delayInMilliseconds)
{
int iNumBytes = numBytes;
INT iRet = 0;

if(Send(Buffer, numBytes) == SOCKET_ERROR)
{
NError::WarningMessage(NInternetComm::GetErrorEntry(GetLastError()));
iNumBytes = -1;
}
return iNumBytes;
}


recive code is like this:

void CClientSock::OnReceive( int nErrorCode )
{


unsigned char TempBuffer[1000];
int Size = Receive(TempBuffer, 1000);
if(m_Buffer.NumElements() + Size > m_Buffer.Size())
{
NError::WarningMessage("Buffer is full in CClientSock (resized)");
m_Buffer.ReSize(m_Buffer.NumElements() + Size);
}

/* The following commented code is to test the connection using known bytes.
const CString TestString("the quick brown fox jumped over the lazy dog THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG 0123456789\n");
static int Place = 0;
static ofstream out("TestOutputOnReceive.txt");
*/
for(int i = 0; i < Size ; i++)
{
m_Buffer.Add(TempBuffer[i]);
}


CSocket::OnReceive(nErrorCode);
}


Thank you again for all your help.

shahin
April 4th, 2005, 11:39 AM
back to top

Anyone has any Idea how I can avoid this peoblem???/

I am trying to stop sending in my server, when I am doing debuging in clinet and client is not reciving. Please, let me know what other type of information I can provide you inorder to make this work.