Solved

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

Posted on 1997-10-14
1
1,506 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
[X]
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
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

Don't Miss ATEN at InfoComm 2017!

Visit booth #2167 to see the  new ATEN VM3200 32 x 32 Modular Matrix Switch. Other highlights include the VE8950 4K HDMI Over IP Extender, VS1912 12-Port DP Video Wall Media Player  and VK2100 ATEN Control System. Register now with Free Pass Code ATEN288!

Question has a verified solution.

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

This article is in response to a question (http://www.experts-exchange.com/Networking/Network_Management/Network_Analysis/Q_28230497.html) here at Experts Exchange. The Original Poster (OP) requires a utility that will accept a list of IP addresses …
Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

718 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