Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with CSocket

Status
Not open for further replies.

HippoTas

Programmer
Dec 4, 2001
15
GR
Hi! I am writting a programm and I want to "speak" with a server. I used CSocket,CSocketFile in order to create two CArchives one for reading and one for writing.
I use the code below :

m_arOut->WriteString(szMessage);
m_arOut->Flush();

while (!m_arIn->IsBufferEmpty())
{
m_arIn->ReadString(strResponse);
}

the problem is that it succeeds to write to the archive but there is no way to read the response.
I tested the server via telnet and it works really fine.
Any suggestion?
 
Just a question. I'm not a network programming expert, but your code is this:

m_arOut->WriteString(szMessage);
m_arOut->Flush();

while (!m_arIn->IsBufferEmpty())
{
m_arIn->ReadString(strResponse);
}

Is it possible that because of timing or network delay, the "in" buffer code is executed immediately (before anything arrives) and the response arrives later?
 
No cause it is in the same computer (localhost) i finally found a solution not using CArchive for the incoming stream but the CSocketFile (m_socketFile.Read())
Thnx for answering :)
 
this is the listing for reading the server's response :

BOOL HSock::ReceiveCommand(CString &strResponse)
{
if ((m_arIn!=NULL)&&(m_arIn->IsLoading()))
{
TRY
{
char c;
while ((m_socketFile->Read(&c,sizeof(c))>0)&&(c='\n'))
strResponse += _T(c);

m_socketFile->Flush();
}
CATCH(CFileException, e)
{
m_arIn->Abort();
delete m_arIn;
m_arOut = NULL;
return (FALSE);
}
END_CATCH
}
return (TRUE);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top