Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello! I'm transferring files from server application folder to client application folder once after the connection is made. I'm giving file name to create new text file in client program. Instead, I want the server to send any kind of message or command to ask the client to create new text file with particular name.

What I have tried:

This is the code in client end where I'm giving filename to create.
int br=SockConnection.Receive(buff,1000);
CFile Destfile;
Destfile.Open(L"Myreceivedfile", CFile::modeCreate | CFile::modeWrite);
Destfile.Write (buff,br);

Instead, I want to server to inform the client to create file with particular name. Pls help. Thank you.
Posted
Comments
Richard MacCutchan 22-Jan-19 5:04am    
Get the server to send the filename as the first message.
rmds 22-Jan-19 5:28am    
Pls correct me if I'm wrong. You mean to say like this?
"SockConnection.Send(L"Myinputfiledata", 0);"
Richard MacCutchan 22-Jan-19 5:53am    
Sort of. But you need to ensure that both client and server understand what each message is about. So a message with the filename should contain some sort of identifier so it is not mistaken for ordinary data. You should design a protocol between your terminals so they can validate the information that is being passed between them. Do not assume that the content of a message is what you think it should be.
rmds 22-Jan-19 7:03am    
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!
Richard MacCutchan 22-Jan-19 7:19am    
I already explained what you need to do. Each message should include a header that identifies what the content of the message is. So to start a new file, send a message with a header plus a file name. To send some file content send a header plus some data. The header should include a flag that identifies the type of record, and a length field that tells the receiver how long the message is.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900