Click here to Skip to main content
15,879,535 members
Articles / Desktop Programming / MFC
Article

Peer-to-Peer Communicator and File Transfer

Rate me:
Please Sign up or sign in to vote.
4.33/5 (57 votes)
14 Aug 20013 min read 390K   21.9K   167   92
Get youself a peer-to-peer communicator and exchange files across a network.

Sample Image - SimpleChat.jpg

Prologue

On this web site you would probably find every functionality that was put into this application. I realize that. Hence I'm not going to post the source code just yet. However, I've put it up here to see how much interest this application would attract, specifically if there is any interest in the techniques that I've used to implement it. I'm going to enumerate some of the techniques in this short article. Let me know if there is anything of interest to you and I will probably write up a separate article for whatever is requested.

Introduction

This is a peer-to-peer communicator that allows you to chat with a single person at a time and exchange files simultaneously.

Sockets, ..., sockets, ... Zzzzzap! (::) (Connection established)

A socket library built upon Berkley sockets was designed and implemented. I've taken a well known approach of having an object package itself into a stream on the sender's side and do the opposite on the receiver side. Using the library above, a hierarchy of classes is introduced to accommodate the file transfer.

Multithreading

A set of classes encapsulate the threading/synchronization Windows API. Each thread is responsible for handling logically separated functional areas of the software. That is, I've introduced:

  • A UI thread.

    This thread is the MFC's main thread that handles all UI components. This thread is a subscriber for event notifications from the rest of the threads.

  • A couple of Listener threads.

    One of which is to listen for incoming requests for the first connection with the remote party to be established. Once the connection is up, another Listener is brought alive to await for any possible requests to send a file.

  • A Sender thread.

    This thread handles the file sending functionality.

  • A Receiver thread.

    This thread handles the file receiving functionality.

Event Model

The Sender and Receiver threads notify the UI thread about the progress of the work by adding notification events into the shared memory queue. The UI thread polls the queue for the notifications every few milliseconds. This approach is good enough for such a simple application, but if I was to have a lot of worker (Hello Microsoft! :)) threads, I should have probably created a dedicated worker thread which all it would do is to sit locked on the queue's mutex, until an event is added and then do UI_Thread::PostThreadMessage(), so that UI would have much faster response to the application events.

Epilogue

I hope by now you're not yelling at the monitor, hoping that I might hear it "Where is the Source Code?!". Well, honestly I don't believe that one can learn a lot from a load of not very well documented source code. So if there are people who want to know, let me know what part of this software would be of most interest to you and I'll come up with an article.

08/15/2001

Well, after getting several emails with the source request, I figured I should probably give it to the community :) Unfortunately I don't have time to explain all of the concepts of the NetLib that is included here, but basically this library allows you in a limited form to marshal an arbitrary C++ object(s) across a network. Some threading and synch classes are included and provider/consumer design pattern is applied for communicating with the UI thread. As soon as I get a brake from work, I'll come up with a better article. Actually let me know if there is a need for it.

Well happy coding to you, I hope this will be of some help.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here



Comments and Discussions

 
GeneralProblems with Memory Pin
LeDaemon3-Jun-03 23:20
LeDaemon3-Jun-03 23:20 
GeneralExcellent work! Pin
aldenhung30-Apr-03 4:25
aldenhung30-Apr-03 4:25 
GeneralRe: Excellent work! Pin
Marat Bedretdinov30-Apr-03 5:07
Marat Bedretdinov30-Apr-03 5:07 
GeneralAnybody know of such an app in JAVA Pin
findneville12-Apr-03 16:09
findneville12-Apr-03 16:09 
GeneralRe: Anybody know of such an app in JAVA Pin
E.T.28-Apr-03 18:05
E.T.28-Apr-03 18:05 
GeneralRe: Anybody know of such an app in JAVA Pin
Anonymous29-Apr-03 2:44
Anonymous29-Apr-03 2:44 
GeneralRe: Anybody know of such an app in JAVA Pin
chenningcheng4-Dec-04 16:00
chenningcheng4-Dec-04 16:00 
GeneralRe: Anybody know of such an app in JAVA Pin
anjolie13-Feb-09 2:56
anjolie13-Feb-09 2:56 
me too....can some one pls send me the java code for this application

anjolie.nair@gmail.com
GeneralVC++ 7 Pin
Meshal15-Nov-02 2:02
Meshal15-Nov-02 2:02 
GeneralRe: VC++ 7 Pin
phamchicong12-Aug-04 23:05
phamchicong12-Aug-04 23:05 
GeneralOut of memory Pin
31-Jan-02 3:17
suss31-Jan-02 3:17 
GeneralRe: Out of memory Pin
chenningcheng10-Dec-04 0:55
chenningcheng10-Dec-04 0:55 
GeneralI had resovled it Pin
24-Jan-02 17:22
suss24-Jan-02 17:22 
QuestionWhy it says not enough memory? Pin
24-Jan-02 15:48
suss24-Jan-02 15:48 
AnswerRe: Why it says not enough memory? Pin
31-Jan-02 3:57
suss31-Jan-02 3:57 
GeneralRe: Why it says not enough memory? Pin
Meshal15-Nov-02 23:38
Meshal15-Nov-02 23:38 
GeneralNasty bug Pin
Jerry Evans9-Nov-01 0:42
Jerry Evans9-Nov-01 0:42 
GeneralRe: Nasty bug Pin
Marat Bedretdinov9-Nov-01 4:35
Marat Bedretdinov9-Nov-01 4:35 
GeneralChinese cannt show properly in win2k! Pin
14-Oct-01 22:40
suss14-Oct-01 22:40 
GeneralRe: Chinese cannt show properly in win2k! Pin
Marat Bedretdinov15-Oct-01 9:09
Marat Bedretdinov15-Oct-01 9:09 
Generaloh~ very nice! Pin
22-Aug-01 17:30
suss22-Aug-01 17:30 
GeneralThanks! and VERY NICE for DEVOTEE such as you Pin
18-Aug-01 20:56
suss18-Aug-01 20:56 
GeneralRe: Thanks! and VERY NICE for DEVOTEE such as you Pin
Marat Bedretdinov19-Aug-01 5:29
Marat Bedretdinov19-Aug-01 5:29 
GeneralThank you Marat, for finally posting the source. I love you Pin
15-Aug-01 11:49
suss15-Aug-01 11:49 
GeneralRe: Thank you Marat, for finally posting the source. I love you Pin
Marat Bedretdinov15-Aug-01 17:39
Marat Bedretdinov15-Aug-01 17:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.