Sockets and using them...

sarn via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Nov 6 01:51:41 PST 2016


On Sunday, 6 November 2016 at 06:02:48 UTC, Era Scarecrow wrote:
>  So I've got a project where I want to create basically a 
> decentralized chat program where every program is a host and a 
> client. When you connect all connections can go through to 
> route the chat to everyone else.
>
>  So to make this work I've looked over the sockets package and 
> I don't quite follow how you'd make it so it works a lot like a 
> web browser, aka when you get a connection you redirect to a 
> different port so you have 1 listening port for new connections 
> so it can act as a server. What settings or configuration would 
> I need to be able to do that?

Web browsers do redirects at the application level.  It's in 
HTTP, which is a protocol built on top of the layer sockets 
provide.

It sounds like you want to do the same thing: design a protocol 
that includes some kind of message that's agreed to mean, "Yo, 
make a new connection on this port."  Basically, any 
off-the-shelf textbook on network protocol design will help you.

One thing I can tell you now, though, is that NATs will be your 
big problem if you try to deploy your system for real.  Most 
machines still use IPv4 and don't have publicly accessible IP 
addresses, so they use network address translation to access the 
internet.  Quirks of different NAT implementations cause huge 
pain to everyone who tries to deploy a peer-to-peer system.

But don't let me put you off :)


More information about the Digitalmars-d-learn mailing list