Solved

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

Posted on 1997-10-14
1
1,450 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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Sometimes you might need to configure routing based not only on destination IP address, but also on a combination of destination IP address (or hostname) and destination port number. I will describe a method how to accomplish this with free tools. …
The Need In an Active Directory enviroment, the PDC emulator provide time synchronization for the domain. This is important since Active Directory uses Kerberos for authentication.  By default, if the time difference between systems is off by more …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

771 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now