Solved

Sending Files in a Client-Server using Visual C++ MFC

Posted on 1997-10-14
1
1,492 Views
Last Modified: 2013-12-23
hi!  I got some problems on how to send a file from a client applicaation to a server application, and vice versa, using Visual C++ MFC (using Sockets).  Thanks for helping!!!
0
Comment
Question by:mallow
1 Comment
 
LVL 1

Accepted Solution

by:
Daniel_E earned 100 total points
ID: 1566397
One easy way is to use CSocketFile. CSocketFile acts in most
cases just like a normal CFile, so you can use Read/Write
directly from/to it. You can even connect a CArchive to it.

The code below needs error-handling, and in the server you
really should start a thread for each incoming connection.
(Otherwise the connection will block others.)

---[client]---
CString server = "10.0.0.1";
int port = 6789;
CSocket sock;
sock.Create();
sock.Connect(server, port);
CSocketFile sfile(&sock);
...
(Do you stuff here. Read/Write to sfile!)
...
sfile.Close();
sock.Close();
---[client]---


---[server]---
int port = 6789;
CSocket sock;
sock.Create(port);
sock.Listen();
CSocket* client;
while (some_condition)
{
   client = new CSocket;
   sock.Accept(*client);
   CSocketFile sfile(client);
   ...
   (Do your stuff here. Start a thread, read/write)
   ...
   sfile.Close();
   client->Close();
   delete client;
}
sock.Close();
---[server]---

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Downtime reduced, data recovered by utilizing an Experts Exchange Business Account Challenge The United States Marine Corps employs more than 200,000 active-duty Marines with operations in four continents, all requiring complex networking system…
This is the first one of a series of articles I’ll be writing to address technical issues that are always referred to as network problems. The network boundaries have changed, therefore having an understanding of how each piece in the network  puzzl…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question