www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Sockets and using them...

reply Era Scarecrow <rtcvb32 yahoo.com> writes:
  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?
Nov 05 2016
next sibling parent reply sarn <sarn theartofmachinery.com> writes:
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 :)
Nov 06 2016
parent Era Scarecrow <rtcvb32 yahoo.com> writes:
On Sunday, 6 November 2016 at 09:51:41 UTC, sarn wrote:
 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.

 <snip>

 Quirks of different NAT implementations cause huge pain to 
 everyone who tries to deploy a peer-to-peer system.
Yeah, I was hoping it would be 'redirect to this port instead' so you wouldn't have to make a new connection. With port forwarding and other issues involved, I can see a big problem. Once you are using a port I'm pretty sure it will be locked (although if multiple can share the same port, I'd be fine with that too, as long as I know what IP address it came from). I suppose I can simply write it and try to get it working...
Nov 06 2016
prev sibling parent Charles Hixson via Digitalmars-d-learn writes:
On 11/05/2016 11:02 PM, Era Scarecrow via Digitalmars-d-learn 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?
That sounds more like a job for udp than tcp sockets. You'd need to implement an ack/nak protocol because udp doesn't guarantee delivery, but unless you want a central server I don't see how you could use tcp. The central server wouldn't need to do much, and could delegate most of the processing, but it wouldn't be decentralized. I was looking into using tcp (actually zmq) for something similar awhile back and tcp just didn't seem to support actually decentralized communication. Udp did...which meant I couldn't use zmq. That was a real pity because zmq is basically a very nice package, and easy to wrap.
Nov 06 2016