Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7929693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:10:19+00:00 2026-06-03T20:10:19+00:00

What I want to do is run the following script on every port, 1025+.

  • 0

What I want to do is run the following script on every port, 1025+. What I am doing is making a Blackjack iPhone app that interacts with this script for online gaming. The thing is, I would want to put this on each port manually by changing the port to listen each time for all the ports. How can I do it so that there is a new table on every port. Each table has an ID the app will check for to see the amount of players and who is at the table.

The socket sets the ID for the Table class, but I need to be on multiple ports to be able to keep that table going and saving every player moves and such.

Bottom line, how can I make this script run on every port, how can I change the listening port by itself, and how can I have python make all Tables by itself on each port?

class Table:
    def __init__(self, id):
        self.players = []
        self.positions = {'1': '', '2': '', '3': '', '4': ''}

    def sit(self, player_id, position):
        self.positions[position] = player_id

# --------------------------------------------- #
# --------------------------------------------- #


class Socket(Protocol):
    def connectionMade(self):
        #self.transport.write("""connected""")
        self.factory.clients.append(self)
        print "Clients are ", self.factory.clients

    def connectionLost(self, reason):
        self.factory.clients.remove(self)

    def dataReceived(self, data):
        #print "data is ", data
        a = data.split(':')
        if len(a) > 1:
            command = a[0]
            content = a[1]



            msg = ""

        print msg

        for c in self.factory.clients:
            c.message(msg)

    def message(self, message):
        self.transport.write(message)


factory = Factory()
factory.protocol = Socket
factory.clients = []

reactor.listenTCP(1025, factory)
print "Blackjack server started"
reactor.run()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:10:22+00:00Added an answer on June 3, 2026 at 8:10 pm

    Answering your question

    You ask:

    • How can I make this script run on every port?
    • How can I change the listening port by itself?
    • How can I have python make all Tables by itself on each port?

    I think the answer here is to simply use a loop to bind the factory to as many ports as you want.
    However, since you’re storing a list of clients in your factory as well, you’ll need to create a new factory for reach port, as well. So something like:

    factories = [ ]
    for i in range(0, NUM_TABLES):
        factory = Factory()
        factory.protocol = Socket()
        factory.clicents = []
        factories.append(factory)
        reactor.listenTCP(1025 + i, factory)
        reactor.run()
    

    You’re using classes, so each factory keeps its own list of clients, each one has its own Socket instance to manage the connection. You don’t show how Table instances are instantiated, but as long as each Socket or Factory instance instantiates and maintains a reference to the Table, this should allow you to have multiple connections, each with its own state.

    By keeping a list of all factories, you can iterate over them to make a list of running games, etc.

    Considering a different architecture

    While the above might work, it’s not how client-server systems are typically architected.
    In particular, your system here requires your client to know what port to use. That may work ad hoc when you’re all in your living room together, but it’s tedious and won’t scale in general.

    What you want is something, like a webserver, that listens on one port to establish the connection, and then tells the client: “hey, your table id is 25, use that whenever you want to talk”. In addition, this means making a list of tables available to the client, so they can pick one. And, you can get fancier from there: a special expiring cookie given to client so that it doesn’t accidentally hack/disturb a game that it’s no longer part of, etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to run the following jquery code on every page in my website.
Suppose I want to run the following method foo() once every hour in Grails:
I have the following code I want to run, but the problem is $this->type
I have the following function that I only want to run inside <div id=imgWrapper>
I want to run the following in batch script where it takes an argument
I have a node.js script on my server that I want to run continuously
I want to run the following command from a C program to read the
I want to run a batch file, which I do via the following: <CustomAction
I have the following sample code which doesn't seem to want to run. import
I have the following tables. I want to run a query but I think

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.