From: "Bernard Delmée" Date: 2001-09-16T21:00:35+09:00 Subject: [ruby-talk:21259] Re: Peer-to-peer "Hal E. Fulton" wrote: > Suppose I wanted to implement a Napster-like > server whose purpose was to enable > communication between peers. How do I get > the clients to talk? Well, I have never programmed anything network-related in ruby, nor sniffed Napster packets, but here's a reasonable (albeit probably naive) scenario: [1] client B contacts server A (on a well known port), publishes list of shared files, and _port_ on which it's listening and willing to serve peer requests [2] client C contacts server A (on same well known port), requesting a file. Server discovers a match in B's list, and directs C to B's listening port. (I don't mean automatic redirection, C needs to explicitly contact B on its advertised port) [3] C serves request(s) on published port Of course clients could be listening/serving on a default ("well known") port, but that'd be overrideable. Handy when for example, B and C (and A for that matter) all run on the same computer. In TCP/IP parlance, no two processes are allowed to bind/listen to the same port on the same system. (the second would get an "address already in use" error or such) So a mere IP address does not identify a communication endpoint; the combined IP:port does. Also note that clients are actually servers as well (P2P), so threading probably is in order (since your server duty may take a while to satisfy a slow client request). HTH, Bernard.