?
Solved

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

Posted on 1997-10-14
1
Medium Priority
?
1,517 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 400 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

ATEN's HDBaseT Presentation at InfoComm 2017

Hear ATEN Product Manager YT Liang review HDBaseT technology, highlighting ATEN’s latest solutions as they relate to real-world applications during her presentation at the HDBaseT booth at InfoComm 2017.

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…
An article on effective troubleshooting
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

765 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