Click here to Skip to main content
16,006,348 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Doc-View and NewFile Pin
Neville Franks20-May-06 13:02
Neville Franks20-May-06 13:02 
GeneralRe: Doc-View and NewFile Pin
faroo2821-May-06 13:45
faroo2821-May-06 13:45 
Questionmd5? Pin
flyskytoday20-May-06 5:36
flyskytoday20-May-06 5:36 
AnswerRe: md5? Pin
Chris Losinger20-May-06 6:33
professionalChris Losinger20-May-06 6:33 
GeneralRe: md5? Pin
flyskytoday21-May-06 3:51
flyskytoday21-May-06 3:51 
QuestionExporting a struc from a DLL Pin
Cyber Friend20-May-06 4:23
Cyber Friend20-May-06 4:23 
AnswerRe: Exporting a struc from a DLL Pin
Cyber Friend20-May-06 6:28
Cyber Friend20-May-06 6:28 
QuestionSockets help Pin
Demian Panello20-May-06 4:08
Demian Panello20-May-06 4:08 
Hi.
I'm writing a server and client application using sockets. And I have a bug that I can't fix.
The server side software, start a thread that create a socket and when a client connect it calls a function to enumerate the folders and files of the PC where the server runs and it sends the names of files and folders to the client:

BOOL EnumerateFolders ()<br />
{<br />
    WIN32_FIND_DATA fd;<br />
<br />
    HANDLE hFind = ::FindFirstFile (_T ("*.*"), &fd);<br />
<br />
<br />
<br />
    if (hFind != INVALID_HANDLE_VALUE) <br />
	{<br />
        do <br />
	{<br />
	CString data = fd.cFileName;<br />
<br />
<br />
        if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) <br />
	{<br />
               <br />
	//Checking for dots<br />
         if (data != _T (".") && data != _T ("..")) <br />
	  {<br />
            TRACE (_T ("%s\n"), fd.cFileName);<br />
<br />
	    ::SetCurrentDirectory (fd.cFileName);<br />
<br />
	    //  Send to client the name of the folder<br />
	   if(send(client, data, data.GetLength()  , 0) == SOCKET_ERROR)<br />
	   {<br />
	     // Error: return<br />
	     return FALSE;<br />
	   }<br />
<br />
	  EnumerateFolders ();<br />
<br />
	  ::SetCurrentDirectory (_T (".."));<br />
         }<br />
			<br />
       }<br />
      else<br />
	{<br />
          // is a file<br />
	  TRACE (_T ("%s\n"), fd.cFileName);<br />
         <br />
         //  Send to client the name of the file<br />
	if(send(client, data, data.GetLength()  , 0) == SOCKET_ERROR)<br />
	{<br />
	  // Error: return<br />
	  return FALSE;<br />
	}<br />
     }<br />
<br />
   } while (::FindNextFile (hFind, &fd));<br />
    <br />
    ::FindClose (hFind);<br />
  }<br />
<br />
return TRUE;<br />
}


At the client side, after the connection, it starts to receive the strings from server, inside a loop that it ends with a particular string.
Inside the loop, (a do-while), I wrote:

if ((numbytes = recv(client, buf, MAXDATASIZE-1, 0)) == -1) <br />
{<br />
  // ERROR<br />
  TRACE("recv: %i bytes", numbytes);<br />
			<br />
  return 1;<br />
}<br />
<br />
temp.Format("%s", buf);<br />
temp.TrimRight ();<br />
// Here I get a very long string <br />


So, the CString object "temp", holds the string sent by the server, it works, I can see the data, but instead of see the name of a single folder or file, I see a very long string with a lot of name of folders and files. It looks like the server send faster than client can receive the items, so the data is being concatenate.
Beside this, I'm trying to write the temp object into a text file using a CStdioFile object, but it assert, maybe because of the large of the string.

Where is the problem here?
How could I perform a receive routine at client side to get the strings for every folder and file sent by server?
Or the problem is in the server routine post above??

I will really appreciate any advice.

Thank you.




Demian.

"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my telephone."

-Bjarne Stroustrup, computer science professor, designer of C++
programming language (1950- )
AnswerRe: Sockets help Pin
Laxman Auti20-May-06 4:25
Laxman Auti20-May-06 4:25 
GeneralRe: Sockets help Pin
Demian Panello20-May-06 7:24
Demian Panello20-May-06 7:24 
GeneralRe: Sockets help Pin
Laxman Auti21-May-06 18:38
Laxman Auti21-May-06 18:38 
QuestionCrash.... Pin
RockyJames20-May-06 2:52
RockyJames20-May-06 2:52 
AnswerRe: Crash.... Pin
Stephen Hewitt20-May-06 4:38
Stephen Hewitt20-May-06 4:38 
QuestionReflection &amp; late binding [modifed] Pin
ey_cat20-May-06 2:38
ey_cat20-May-06 2:38 
AnswerRe: Reflection &amp; late binding [modifed] Pin
Laxman Auti20-May-06 3:53
Laxman Auti20-May-06 3:53 
GeneralRe: Reflection &amp; late binding [modifed] Pin
ey_cat20-May-06 9:32
ey_cat20-May-06 9:32 
QuestionAbout Runtime class Pin
Ramu.e20-May-06 1:58
Ramu.e20-May-06 1:58 
AnswerRe: About Runtime class Pin
Hamid_RT20-May-06 2:01
Hamid_RT20-May-06 2:01 
AnswerRe: About Runtime class Pin
Laxman Auti20-May-06 2:11
Laxman Auti20-May-06 2:11 
GeneralRe: About Runtime class Pin
Ramu.e21-May-06 22:59
Ramu.e21-May-06 22:59 
GeneralRe: About Runtime class Pin
Laxman Auti21-May-06 23:34
Laxman Auti21-May-06 23:34 
QuestionAlphaBlend Method Pin
_raghu20-May-06 1:17
_raghu20-May-06 1:17 
AnswerRe: AlphaBlend Method Pin
Monty220-May-06 1:33
Monty220-May-06 1:33 
GeneralRe: AlphaBlend Method Pin
_raghu20-May-06 1:45
_raghu20-May-06 1:45 
GeneralRe: AlphaBlend Method Pin
Monty220-May-06 1:53
Monty220-May-06 1:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.