Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 1997-10-14
1
1,483 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

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

Question has a verified solution.

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

Have you ever set up your wireless router at home or in the office to find that you little pop-up bubble in the bottom right-hand corner of Windows read "IP Conflict - One of more computers on the network have been assigned the following IP address"…
Resolve DNS query failed errors for Exchange
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

840 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