Click here to Skip to main content
15,914,387 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Which lib is corresponding to Dskquota.h? Pin
Lakitu18-Sep-02 4:19
Lakitu18-Sep-02 4:19 
GeneralRe: Which lib is corresponding to Dskquota.h? Pin
Anonymous18-Sep-02 4:46
Anonymous18-Sep-02 4:46 
GeneralRe: Which lib is corresponding to Dskquota.h? Pin
Le centriste18-Sep-02 6:22
Le centriste18-Sep-02 6:22 
GeneralRe: Which lib is corresponding to Dskquota.h? Pin
Anonymous18-Sep-02 8:04
Anonymous18-Sep-02 8:04 
GeneralMaking Right align Rich Edit box ! Pin
Hadi Rezaee18-Sep-02 4:07
Hadi Rezaee18-Sep-02 4:07 
GeneralProblem with SQL FETCH Pin
Cheickna18-Sep-02 4:04
Cheickna18-Sep-02 4:04 
GeneralRe: Problem with SQL FETCH Pin
TyMatthews18-Sep-02 5:10
TyMatthews18-Sep-02 5:10 
GeneralPassing a file through a Socket Pin
RobJones18-Sep-02 3:44
RobJones18-Sep-02 3:44 
Hello,
I am trying to pass a file through a Socket plus I would like to send the name of the file also.. Here is my source for sending the file. (I'll tell you my problem at the end)
void CClientDlg::OnBAttach() // button to attach a file and send it
{
	CSocket* cSocket = new CSocket();
	cSocket->Create();
	cSocket->Connect((LPCTSTR(m_strServerIP)),m_iFtPort);
			
	static char BASED_CODE szFilter[] = "All Files (*.*)|*.*||";
												
	CString strPath;
	CFileDialog m_ldFile(TRUE,".*",strPath,
		OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter);
	
	// Initialize the starting directory
	m_ldFile.m_ofn.lpstrInitialDir = _T("C:\\");

	// Show the file open dialog and caputre the result
	if (m_ldFile.DoModal() == IDOK)
	{
		// Get the filename selected
		strPath = m_ldFile.GetPathName();		
		
		CFile myFile;
		myFile.Open(strPath, CFile::modeRead | CFile::typeBinary);

		// CString strFileName;
		// strFileName = "FILE"+myFile.GetFileName();
		// cSocket->Send(((LPCTSTR(strFileName),4096);

		long nRead;
		do
		{
		   byte* data = new byte[4096];
		   
		   nRead = myFile.Read(data, 4096);
		   cSocket->Send(data, nRead);
		   
		   delete data;   	
		}
		while (nRead > 0);
			
		// Clean up
		myFile.Close(); 
	}

	cSocket->Close();
	delete cSocket;
}


And for my Receive function on the "Server" side

long nRead;
	do
	{
		byte* data = new byte[4096];
		nRead = pSocket->Receive(data, 4096);
		m_destFile.Write(data, nRead); // Write it
		delete data;
	}
	while (nRead > 0);


I can't figure out a good way to get the file name, plus when I receive the file like this, sometimes the file ends up a few bytes longer than the source(sending) file and sometimes the file comes across perfect..
On my accept function I create a pre defined file for receiving and I open it for reading.. then in my receive I start writing to the file. When the client disconnects I close the file.. This just doesn't seem like a good way to pass files through a socket.. anyone have any better ways of doing this. I have been beating my head against the wall for days. I can't find any examples on MSDN and I found only 1 example at codeguru.com

Thanks for any suggestions.

Rob
GeneralRe: Passing a file through a Socket Pin
TyMatthews18-Sep-02 5:57
TyMatthews18-Sep-02 5:57 
GeneralRe: Passing a file through a Socket Pin
Bilal18-Sep-02 6:32
Bilal18-Sep-02 6:32 
GeneralRe: Passing a file through a Socket Pin
RobJones18-Sep-02 6:57
RobJones18-Sep-02 6:57 
GeneralRe: Passing a file through a Socket Pin
RobJones18-Sep-02 11:06
RobJones18-Sep-02 11:06 
GeneralRe: Passing a file through a Socket Pin
Bilal18-Sep-02 20:42
Bilal18-Sep-02 20:42 
GeneralUTF-8 to Unicode or ANSI. Pin
Halls18-Sep-02 3:25
Halls18-Sep-02 3:25 
GeneralRe: UTF-8 to Unicode or ANSI. Pin
Stephane Rodriguez.18-Sep-02 3:37
Stephane Rodriguez.18-Sep-02 3:37 
GeneralAfxBeginThread Pin
vampiras^18-Sep-02 3:15
sussvampiras^18-Sep-02 3:15 
GeneralRe: AfxBeginThread Pin
Chris Meech18-Sep-02 3:55
Chris Meech18-Sep-02 3:55 
QuestionHow to pass address of a method to a function Pin
Raphael Kindt18-Sep-02 3:06
Raphael Kindt18-Sep-02 3:06 
AnswerRe: How to pass address of a method to a function Pin
Stephane Rodriguez.18-Sep-02 3:40
Stephane Rodriguez.18-Sep-02 3:40 
AnswerRe: How to pass address of a method to a function Pin
Joaquín M López Muñoz18-Sep-02 4:08
Joaquín M López Muñoz18-Sep-02 4:08 
AnswerRe: How to pass address of a method to a function Pin
Axter18-Sep-02 5:16
professionalAxter18-Sep-02 5:16 
Generalstd::string Pin
Furrukh18-Sep-02 2:15
Furrukh18-Sep-02 2:15 
GeneralRe: std::string Pin
jhwurmbach18-Sep-02 2:31
jhwurmbach18-Sep-02 2:31 
GeneralRe: std::string Pin
Joaquín M López Muñoz18-Sep-02 4:05
Joaquín M López Muñoz18-Sep-02 4:05 
GeneralRe: std::string Pin
Axter18-Sep-02 5:31
professionalAxter18-Sep-02 5:31 

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.