So, I have just started with C++ Sockets. Got the program to get headers from various servers just right today, and am aiming to make an IRC bot in under a month to perfect those basics. In the long term(less than an year), I am aiming to make a P2P messaging system, and maybe a file sharing/resources sharing network in the future. I am not sure of the entire process and the skills and knowledge I require.

I guess Sockets are definitely required? I also don't understand a lot of the basics, like how a P2P program is able to connect to various peers all at once when a socket can only support one connection at a time. Does it use UDP or TCP to send the packets? Since the order of the reaching of packets is not important in some P2P networks, they don't need to use TCP, I guess, like BitTorrent? I was reading up the topic in a book, and there were a lot of things explained like DHT and various algorithms, of which I have got the hang of only a part of things. I understand what a DHT is. Don't understand a majority of the other things. Can you guys give me tips or good books where the basics are properly explained?

As is obvious, my prior knowledge of networking is very weak, just upto the OSI stack, how packets are sent and stuff. Nothing more.

Dani AI

Generated

Short answer for : yes, sockets are the right place to start. A listening socket only accepts new connections; each successful accept() returns a new socket file descriptor that represents one peer connection, so a server actually holds many sockets at once. To handle lots of peers you either spawn threads/processes or (more commonly for scale) use non‑blocking I/O and an event loop (select/poll/epoll) to multiplex many sockets in one process. This is exactly the pattern used by chat servers and IRC implementations; for the same mechanism works on a home LAN — start by getting a multi‑client server working locally. (beej.us)

About TCP vs UDP: use TCP when you need reliable, ordered streams; use UDP when you want low latency or plan to implement your own reliability/ordering. Many real P2P systems mix transports: BitTorrent’s peer wire protocol runs over TCP (and also supports uTP, a UDP‑based transport), while the BitTorrent Mainline DHT runs over UDP for low‑overhead lookups. Learn the transport tradeoffs before choosing one for messaging vs bulk transfer. (rfc-editor.org)

Expect NAT and firewalls to be the hardest problem. Start with a simple bootstrap/rendezvous server (tracker or signaling server) so peers can discover each other, then add NAT traversal techniques (STUN/ICE and UDP/TCP hole‑punching) and finally relay fallbacks (TURN) for the cases that fail. Make connection logic tolerant: timeouts, retries, and clean fallbacks are essential. (rfc-editor.org)

Practical path and resources: (1) finish your IRC bot to master sockets+concurrency; (2) build a small multi‑client server and an explicit peer‑discovery server; (3) implement direct peer connections with NAT traversal; (4) only then tackle a DHT (read the Kademlia paper) or reuse a battle‑tested library. Recommended reads/tools: Beej’s Guide for hands‑on sockets, Stevens’ UNIX Network Programming for depth, the Kademlia paper for DHT design, and libtorrent if you need a mature C++ BitTorrent stack instead of reimplementing everything. Test on LAN and in VMs/containers before exposing to the public Internet. (beej.us)

I also understand the P2P concept being that any peer can be the server and any can be the client. So, there is the client and server code on every computer.

I run programs in quickbasic and c on my home computers which are networked. 20 years ago folks figured out how to use the ethernet to connect these programs. Their system automatically takes data from one user written C program in one computer and moves to a similar program in another computer. This must be a monumental task because I can't even do it with the serial port yet and Ethernet is many times tougher. I wish I could find some help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.