Click here to Skip to main content
Click here to Skip to main content

Peer-to-Peer Communicator and File Transfer

, 14 Aug 2001
Rate this:
Please Sign up or sign in to vote.
Get youself a peer-to-peer communicator and exchange files across a network.

Sample Image - SimpleChat.jpg


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.


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! (:Smile | :) (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.


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! Smile | :) ) 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.


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.


Well, after getting several emails with the source request, I figured I should probably give it to the community Smile | :) 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.


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


About the Author

Comments and Discussions

GeneralMy vote of 1 Pinmemberamit9051015-Nov-14 23:02 
QuestionPeer-to-Peer Communicator and File Transfer PinmemberMember 1003840117-May-13 10:38 
GeneralMy vote of 5 PinmemberMember 43208447-May-12 10:42 
Questionhow to run the program...??? PinmemberMember 861304130-Mar-12 1:36 
Questionhow to run the program Pinmembermax_lord21-Oct-10 22:31 
Generalproblem Pinmemberdonon25-Jan-10 21:51 
Generallooking for the more clear article PinmemberMember 417159017-Nov-09 5:52 
General[Message Deleted] Pinmemberit.ragester2-Apr-09 22:53 
GeneralThank you PinmemberLi Shu30-Oct-08 3:46 
GeneralVS 2005 Pinmemberewasta12-May-08 11:15 
AnswerRe: VS 2005 PinmemberItai Basel24-Jun-08 10:09 
GeneralRe: VS 2005 PinmemberKristof Nacsa20-Jun-14 9:31 
Generalquestion Pinmembersajjad alizadeh9-May-08 7:47 
Questionfile transfer with peer to peer network ? Pinmemberbenard4-Mar-08 5:11 
QuestionNat Traversal? Pinmemberbluewater02092-Mar-08 22:36 
Thanks for your work!I want to know the detail about nat traversal!Hope your article!
Generalfatal error C1083 Pinmemberleenkinpark30531-Oct-07 20:12 
Questiontransfer file Pinmemberhwzmail9-Oct-07 0:27 
Generalthe progrem use too mach memory! Pinmembertwblue25-Jun-07 0:13 
GeneralRe: the progrem use too mach memory! Pinmemberjan bont31-Jul-08 4:10 
AnswerRe: the progrem use too mach memory! PinmemberDr. B.M. Linden11-Sep-09 10:03 
Questiondoes it resolve domain names? Pinmemberbreakpoint27-Mar-06 21:32 
GeneralRe: peer to peer file transfer PinmemberFabianSauer21-May-06 22:06 
Questionhow to compile and create an exe file Pinmemberhow jack21-Feb-06 16:48 
QuestionSending unicode characters over the network? PinmemberJockeP21-Nov-05 5:17 
QuestionFile Transfer via Serial Port between 2 pc's Pinmembermayurshsawant8110-Nov-05 7:17 
Generaldata transfer receive and send PinsussNIdoh5-Sep-05 22:11 
GeneralPlease help me!I get a access violation in " m_data.m_bDir = h.IsDirectory();" PinmemberMichael sun25-Jul-05 4:20 
Generalhelp me ,out of memory, I am looking for this java app Pinmemberchenningcheng10-Dec-04 2:00 
Questionhow to assign a specific ip address to server and client Pinmembersyaks28-Oct-04 2:54 
QuestionCan anyone Send me the compiled version Pinsussdreammiku24-Aug-04 10:10 
GeneralThanks... Pinmemberbellerofonte13-Aug-04 4:42 
GeneralRe: Thanks... PinmemberMarat Bedretdinov16-Aug-04 10:05 
QuestionHow to increase the speed of transmission? Pinmemberwiskey15-Jun-04 17:40 
QuestionHow to read a file from remote machine PinmemberKmAshif27-Apr-04 5:00 
Generalbob PinsussAnonymous30-Mar-04 17:57 
GeneralIt's great! Pinmemberrong.xia6-Mar-04 17:03 
GeneralPeer to Peer communication in network sharing PinmemberAtif Mushtaq29-Aug-03 22:10 
GeneralRe: Peer to Peer communication in network sharing PinmemberBharath Chopra12-Apr-04 2:25 
GeneralRe: Peer to Peer communication in network sharing PinmemberAtif Mushtaq12-Apr-04 5:39 
GeneralRe: Peer to Peer communication in network sharing Pinmemberyanping wang15-Jul-05 2:10 
GeneralHELP Pinsussfjour1-Jul-03 19:24 
Generala question about NAT PinsussAnonymous11-Jun-03 23:55 
GeneralRe: a question about NAT PinmemberMarat Bedretdinov12-Jun-03 10:57 
GeneralProblems with Memory PinmemberLeDaemon4-Jun-03 0:20 
GeneralExcellent work! Pinmemberaldenhung30-Apr-03 5:25 
GeneralRe: Excellent work! PinmemberMarat Bedretdinov30-Apr-03 6:07 
GeneralAnybody know of such an app in JAVA Pinmemberfindneville12-Apr-03 17:09 
GeneralRe: Anybody know of such an app in JAVA PinmemberE.T.28-Apr-03 19:05 
GeneralRe: Anybody know of such an app in JAVA PinsussAnonymous29-Apr-03 3:44 
GeneralRe: Anybody know of such an app in JAVA Pinmemberchenningcheng4-Dec-04 17:00 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150414.1 | Last Updated 15 Aug 2001
Article Copyright 2001 by Marat Bedretdinov
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid