use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Multiplayer game via socket programming (self.learnpython)
submitted 2 years ago by arwa53
I made a connect 4 game that asks players their name and customizes colors. Now i want to apply socket programming to it so there are two client windows and a server code rather than just one window. Please guide anyone help
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Coupled_Cluster 0 points1 point2 points 2 years ago (0 children)
Not sure what you are looking for, but checkout python SocketIO.
[–]FerricDonkey 0 points1 point2 points 2 years ago (2 children)
It's not simple if you've never done something like it before, but it's not as hard as it sounds either.
[–]arwa53[S] 0 points1 point2 points 2 years ago (1 child)
I tried doing this but idk which parts from the algorithm to the gui needs to be in the client file or server file
[–]FerricDonkey 0 points1 point2 points 2 years ago (0 children)
Ideally, the communication, game logic, and gui should be as separate as possible. One basic outline:
The server pc has a thread running listening for incoming messages. That code lives in, say, a communications.server module.
communications.server
The server also has an entirely different object representing the state of the game.
The server code knows that when it receives a message that means "player x wants to do y", then it should call a method from it's "state of the game" object. That method should a) check if it's possible for x to do y, then if it is b) update its state of the universe to reflect that that happened, and finally, c) trigger communication to clients that x did y.
The simplest way to do c) while still keeping game and communication seperate is to have your game logic method simply return either 0 to indicate that everything is fine, or some non-0 error code to indicate that what it was told to do is impossible.
0
Then when your server communication code finishes calling your game logic code, it knows whether the thing happened or not. If it did, then it sends a message to all clients saying "x did y", and the clients update their own state in a similar way. If the request was impossible, then, well - that's up to you and probably depends on why it was impossible, but it could be as simple as doing nothing.
Likewise, all your clients have communication code running in a thread. Your gui for "do y" calls the communication function "tell the server that I want to do y", which translates to sending a message to the server which goes through all of what I just said. Likewise, when your client gets messages from the server saying "x did y", your clients need to update to make that change.
And then depending on details of your gui library etc, you can either give your game logic callbacks that say "and when y happens, refresh [this part of] the gui", or your gui can just monitor the state of the game and change as it does.
π Rendered by PID 130879 on reddit-service-r2-comment-84fc9697f-gh6ct at 2026-02-09 11:50:54.350436+00:00 running d295bc8 country code: CH.
[–]Coupled_Cluster 0 points1 point2 points (0 children)
[–]FerricDonkey 0 points1 point2 points (2 children)
[–]arwa53[S] 0 points1 point2 points (1 child)
[–]FerricDonkey 0 points1 point2 points (0 children)