It's just standard network software code. There's nothing special about Bitcoin or P2P software in this regard. It just combines client side software with server side software. Of course it requires having multiple threads/processes, but you should already be doing that for server side software anyways.
As with any client software, outgoing connections are made with random ports assigned by the operating system. Using standard system calls, a TCP connection will be opened by the OS using whatever port the OS decides. It works in the same way any software would to make connections to a server.
As with any server software, incoming connections are handled using standard system calls (such as accept, poll, select, etc.) and then passed off to other threads for processing. It works in the same way that any server software does to accept incoming connections.
|