15,891,777 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by rmds (Top 30 by date)
rmds
1-Feb-19 5:47am
View
Here's the snippet:
SERVER SIDE:
command_header.command = SEND_FILE;
command_header.iDataBuffer = findfile.cFileName;
int nfRet = SockConnection.Send((char*)&command_header.command,
sizeof(command_header.command));
size_t iDataLen = command_header.iDataBuffer.GetLength() * sizeof(TCHAR);
nfRet = SockConnection.Send((char*)command_header.iDataBuffer.GetBuffer(),iDataLen);
switch(command_header.command) {
case SEND_FILE: {
CFile Sourcefile;
Sourcefile.Open(Filepath, CFile::modeRead);
ULONGLONG dwLength = Sourcefile.GetLength();
command_header.DataBuffer = new char[(int)dwLength + 1];
UINT nActual = Sourcefile.Read(command_header.DataBuffer,dwLength);
command_header.DataBuffer[nActual] = 0;
nfRet = SockConnection.Send(command_header.DataBuffer, nActual);
CLIENT SIDE:
COMMAND_HEADER hCommand_header;
CFile Destfile;
char nBuf[1000];
int nRet = SockConnection.Receive((char*)&hCommand_header.command,
sizeof(hCommand_header.command));
nRet = SockConnection.Receive((char*)hCommand_header.iDataBuffer.GetBuffer(50),
50*sizeof(TCHAR));
hCommand_header.iDataBuffer.ReleaseBuffer(nRet/sizeof(TCHAR));
here: hCommand_header.iDataBuffer still has junk that was not the case in CREATE_FILE command.
rmds
1-Feb-19 5:33am
View
Could you please lemme know how you comeup with the calculation of GetBuffer() and ReleaseBuffer()? This is pure mastermind!!! and it worked for CREATE_FILE Command. But, wen I'm changing command to SEND_FILE, hCommand_header.iDataBuffer still has garbage values. thank you very much
rmds
31-Jan-19 7:44am
View
I hate to trouble but been checking for quite a while now... A txtfile with the name is created, however the above code crashes with error dialog"Heap Corruption Detected: after Normal block. "CRT detected that the application wrote to memory end of heap buffer". It crashes when I press F10 after "DestFile.Open" in following code:
switch(hCommand_header.command) {
case CREATE_FILE: {
nRet = SockConnection.Receive((char*)hCommand_header.iDataBuffer.GetBuffer(),50);
(hCommand_header.iDataBuffer.GetBuffer())[nRet] = '\0';
Destfile.Open(hCommand_header.iDataBuffer, CFile::modeCreate | CFile::modeWrite);
}
hCommand_header.iDataBuffer.ReleaseBuffer();
break;
rmds
31-Jan-19 5:14am
View
I got it. It worked! Thank you very much!!!
rmds
31-Jan-19 5:04am
View
OK...instead this code reads the filename but along with the garbage value:
int nRet = SockConnection.Receive((char*)&hCommand_header.command,
sizeof(hCommand_header.command));
switch(hCommand_header.command) {
case CREATE_FILE: {
nRet = SockConnection.Receive((char*)hCommand_header.iDataBuffer.GetBuffer(), 50);
}
break;
how to get rid of the garbage and unpack the filename to CString?
rmds
31-Jan-19 4:42am
View
Thank you, it says a lot! I tried above however, still receiving client not getting the filename. Here's my client end code:
COMMAND_HEADER hCommand_header;
CString fname[50];
int nRet = SockConnection.Receive((char*)&hCommand_header, sizeof(hCommand_header));
switch(hCommand_header.command) {
case CREATE_FILE: {
nRet = SockConnection.Receive((char*)&hCommand_header.iDataBuffer, 50); // instead I
// also tried this:
nRet = SockConnection.Receive(fname, 50);
}
break;
Thank you!
rmds
29-Jan-19 1:34am
View
Actually mine is char* to struct. Tried:
method 1. memcpy(command_header.Message_Buffer, buffer, nActual);
buffer[nActual] = '\0';
method 2. memset(command_header.DataBuffer, '\0', sizeof(command_header.DataBuffer));
strcpy(command_header.DataBuffer, buffer);
Both these methods reads data along with junk values too.
rmds
28-Jan-19 23:26pm
View
Agreed! Pls help me get rid of garbage values in above situation. Thank you
rmds
28-Jan-19 13:39pm
View
Thanks much...Somehow this memcpy reads garbage values too at the end...Here's what I tried:
memcpy(command_header.Message_Buffer, buffer, /*min(1000, nActual)*/nActual);
buffer[nActual] = '\0';
int nRet = m_SocketConnection.Send((char*)&command_header,
sizeof(command_header));
rmds
28-Jan-19 7:04am
View
command_header is an object structure Command_Data. and Yes, I'm reading the data from SourceFile into that buffer. I also changed the definition of command data to:
struct Command_Data {
char message[1000];
};
All I want is copy the buffer which contains data from file into this 'char message[1000]' in above struct.
rmds
28-Jan-19 6:08am
View
Thank you, but the code posted already is pretty much all of it.
By the way I found way to type cast from char* to struct.
"Command_Data* tmp_str = reinterpret_cast<Command_Data*>(buffer);"
Now, gotta copy this data into [Command_Data message buffer]. I changed it to array.. How to do this?
rmds
28-Jan-19 5:35am
View
My bad! I missed these...
COMMAND_HEADER command_header;
command_header.command = SEND_FILE;
ULONGLONG dwLength = Sourcefile.GetLength();
char* buffer = new char[(int)dwLength + 1];
buffer[dwLength] = 0;
UINT nActual = Sourcefile.Read(buffer, dwLength);
Command_Data *tmp_str = (Command_Data *)buffer;
//Buffer contains text file.
int nfRet = SockConnection.Send((char*)&command_header, sizeof(command_header));
//Command_Data *tmp_str = (Command_Data *)buffer;//trying to type cast from char* to struct.
rmds
26-Jan-19 8:37am
View
The link goes to surface download page!!!
rmds
24-Jan-19 23:56pm
View
Thank you rick and richard!
rmds
24-Jan-19 2:38am
View
Can you please give me glimpse of header you're referring to with message, length and command. Just wanna see how it looks like to get an idea to implement. Thank you
rmds
23-Jan-19 6:52am
View
After going through lot, i did this...
Server:
typedef struct{
char* filename[20];
}Data_Buffer;
Data_Buffer data_buffer;
data_buffer.filename[21] = "myinputfile";
int nRet = SockConnection.Send((void*)&data_buffer, sizeof(data_buffer));
Client:
typedef struct{
char* filename[21];
}Data_Buffer;
Data_Buffer data_buffer;
int nRet = SockConnection.Receive((void*)&data_buffer, sizeof(data_buffer));
CFile Destfile;
CString filename = (LPCTSTR)&data_buffer;
Destfile.Open(filename, CFile::modeCreate | CFile::modeWrite);
Destfile.Write(Buf, br);
I get file name as garbage values.. What went wrong?
rmds
23-Jan-19 5:37am
View
I really appreciate your time for this. Could you please clarify is this what you mean by header? :
typedef struct COMMAND_HEADER {
char* SET_FILE_NAME;
int data_size;
}
please correct me if I'm wrong
rmds
23-Jan-19 0:33am
View
I understand but, I never actually done it. I'm trying since yesterday but unable to find how the send() with command header looks like. Can atleast show me glimpse of send() with command header with any kind of example? Thank you very much.
rmds
22-Jan-19 7:03am
View
Explanation is crystal clear! Let's say I have multiple Receive() in client application and I'm in need to send message or data from server. How to send the message to specific Receive()? I indeed googled for examples but no luck. Please throw some light with example. Thank you!
rmds
22-Jan-19 5:28am
View
Pls correct me if I'm wrong. You mean to say like this?
"SockConnection.Send(L"Myinputfiledata", 0);"
rmds
21-Jan-19 12:46pm
View
Is there a way to save the file to drive... instead of CFile::ModeCreate and then write into file? I dont wanna create file and then write into it. Thanks!
rmds
21-Jan-19 12:33pm
View
I also have another doubt. I'm sending file from server to client using CSocket. I'm calling Socketid.Receive() in client end. Where the text file will be received? Here's the snippet.
"Server-end"
ULONGLONG dwLength = sourceFile.GetLength();
char* buffer = new char[(int)dwLength + 1];
buffer[dwLength] = 0;
UINT nActual = sourceFile.Read(buffer, dwLength);
if(DataBytes == SOCKET_ERROR) {
AfxMessageBox(L"Error while sending");
return;
}
nActual = nActual - DataBytes;
}
"Client-End"
char *pBuf =new char [1025];
CString strData;
int iLen;
iLen=m_SocketClient.Receive(pBuf,1024);
After I run this code, I'm not finding any text file in Client Folder.
rmds
21-Jan-19 12:23pm
View
Thanks! you're eye opener
rmds
21-Jan-19 8:20am
View
I don't get it.
rmds
21-Jan-19 8:19am
View
This is what I get in lBytesRead in debugging
"lBytesRead 44 unsigned int"
rmds
21-Jan-19 8:19am
View
This is what I get in lBytesRead in debugging
"lBytesRead 44 unsigned int"
rmds
19-Jan-19 0:59am
View
The purpose here to transfer files through MFC socket. Using copyfile() doesn't serve the purpose. Any input would be greatly appreciated. Thanks!
rmds
17-Jan-19 0:34am
View
I'm not particularly using any button to transfer file. Once connection is made, the file should be transferred from server folder to client folder in same computer.
rmds
16-Jan-19 1:14am
View
Now I'm able to spy and notify any changes in directory. How to send the modified files to other connected client application? Do I need to implement thread or any simple method available?
rmds
16-Jan-19 0:58am
View
That was really helpful! tqvm...
Show More