Learning python networking

Paul Pittlerson menkomigen6 at gmail.com
Wed Jan 8 17:27:50 EST 2014


I'm trying to learn about socket, how to create and handle connections in python.

This is the best I could come up with on my own, please take a look and give me critique:
Server script:
http://pastebin.com/KtapYfM0

Client script:
http://pastebin.com/t4dYygmX

How to run it:
I open 3 terminals, in one I start the server script, and enter into it something like 'accept 2'

Then in the two other terminals I start client scripts which will "connect to the server" so to speak.

Now I can communicate between them by sending messages, and exit the whole operation by typing 'exit' into the server.

Is the code overly complicated? More precisely: is there a more elegant and simple way to achieve the same thing? Some people have mentioned things like twisted and asyncore, but I don't know anything about them. If it turns out this kind of concept is very straight forward to set up in either of those I would be interested in sample code.

I'm specifically looking into this kind of communication because I want to make a small multiplayer game.



More information about the Python-list mailing list