[Tutor] sockets, servers, clients, broadcasts...?
Alex Hall
mehgcap at gmail.com
Fri Jun 4 20:17:58 CEST 2010
Thanks for the suggestions, everyone. For now, more as a way to
introduce myself to all this, I am going to have my program
automatically start a server and pop up that server's ip. Then, if you
want, you can type in an ip and connect to the server at that ip
(ports are hard-coded at 7777). That way everyone is a server and a
client, and either you connect to someone else as a client or they
connect to you as a client. It appears, though, that I need a loop to
have a server make any sense at all, to handle incoming data and
connection requests. Obviously, starting this loop will then put the
rest of my program on hold. Am I safe to use basic threading to stick
the server's loop into a new thread? That is, will the rest of my
program be able to talk to the server / will the server be able to
talk to my program from its new home in its separate thread, and might
I run into strange problems because of process scheduling and blocking
(or not blocking)?
On 6/4/10, spir <denis.spir at gmail.com> wrote:
> On Thu, 3 Jun 2010 18:03:34 -0400
> Alex Hall <mehgcap at gmail.com> wrote:
>
>> Hi all,
>> I am a CS major, so I have had the required networking class. I get
>> the principles of networking, sockets, and packets, but I have never
>> had to actually implement any such principles in any program. Now I
>> have this Battleship game (not a school assignment, just a summer
>> project) that I am trying to make playable over the internet, since I
>> have not written the AI and playing Battleship against oneself is
>> rather boring.
>>
>> Right now I am just trying to figure out how to implement something
>> like the following:
>> *you start the program and select "online game"
>> *you select "server" or "client" (say you choose "server")
>> *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.
>>
>> 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.
>> 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? Not a big deal if
>> they are, but I am not sure. Does someone have an example of this
>> process?
>
> I'm far to be a specialist in this field, so this is just reasoning by
> watching your requirements.
>
> First, such a game seems to match peer-to-peer relation. This would be
> different if you implemented complicated game logic, like in the case of an
> AI playing.
> For peers to connect, a general solution is them to register on a dedicated
> public interface (the same can be used to publish a server's IP, indeed).
> Then, your app first reads data there to know which (address,port) pair(s)
> are available.
> But since you seem to be still exploring data exchange issues, you'd better
> concentrate on this basic mechanism first, choose and try one of numerous
> possible solutions, then only address higher-level problems. In the
> meanwhile, just put IPs and ports in a config file or even hardcode them as
> constants.
>
> About client-server, as said above, this model does not really seem to match
> your use case, I guess. But this is still an interesting alternative. I
> would set my own post as server and players as clients. So, when playing
> myself, I would be a local client. This indeed allows two other guys playing
> using your post as server (and you maybe watching the game ;-).
> But this does not make much sense if the server does not have any relevant
> info to deliver (eg playing hints).
>
>
> Denis
> ________________________________
>
> vit esse estrany ☣
>
> spir.wikidot.com
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
--
Have a great day,
Alex (msg sent from GMail website)
mehgcap at gmail.com; http://www.facebook.com/mehgcap
More information about the Tutor
mailing list