[Tutor] sockets, servers, clients, broadcasts...?

Alan Gauld alan.gauld at btinternet.com
Fri Jun 4 00:58:54 CEST 2010


"Alex Hall" <mehgcap at gmail.com> wrote

> *somehow, your instance of the program starts up a server that
> broadcasts something; your enemy has selected "client", and is now
> (SOMEHOW) listening for the signal your server is broadcasting
> *the signal is picked up, and, SOMEHOW, you and your opponent 
> connect
> and can start sending and receiving data.

You can use IP broadcasts to do this but its not very
network friendly. The usual approach is for the IP address/port
to be published in some way - thats how email, ftp, the web etc
all work. The ports are standardised(25 for SMTP, 80 for WWW etc)
but the IP address needs to be published. I'd certainly start with 
that
approach and add broadcast and auro-discovery as a feature later.

> First, how does the client know where to look for the server? I am 
> not
> above popping up the server's ip and making the client type it in, 
> but
> a better solution would be great.

I'd get it working using a fixed IP first, wiorry about broadcasting
after the basics are there.

> How do I make it so that the client can find the server correctly? 
> The
> above IP is one thing, but are ports important here?

Yes, you need IP address plus port number. Best done in a config file
or similar. For peer to peer you can have a list of addresses and
poll them till you get a response but if you are using DHCP you will
need a range and broadcast starts to be better. For now I'd stick with
each process displaing the IP address and the users typing them in.

> they are, but I am not sure. Does someone have an example of this
> process?

Any internet protocol, incluiding SMTP email or FTP...

For a more peer to peer approach think about IM clients.
Netmeeting etc

> from a programming perspective, in any language. For now, it is all 
> a
> frustrating and confusing tangle of Socket objects and low-level
> calls,

Get the basics first. You still need to work out your command
protocol to play the game. That will be challenging enough to start
with.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list