In this tutorial, weβll walk through building a real-time auction system using Python sockets, Tkinter GUIs, and SQLite. Youβll learn how the server works, how clients connect, and how auctions and bids update live.
π Full repository: https://github.com/rogers-cyber/auction-management-system
GitHub
π What Youβll Build
βοΈ A server that manages auctions and bid storage
βοΈ An Admin app to create and manage auctions
βοΈ A Bidder app to see auctions and place bids
βοΈ Real-time updates across all apps via sockets
π§± 1. Initialize the Database
Inside server.py, we create an SQLite database that stores auctions and bids.
def init_db():
conn = sqlite3.connect(DB_FILE)
c = conn.cursor()
c.execute("""
CREATE TABLE IF NOT EXISTS auctions (
item_id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
...
status TEXT DEFAULT 'ACTIVE'
)
""")
c.execute("""
CREATE TABLE IF NOT EXISTS bids (
bid_id INTEGER PRIMARY KEY AUTOINCREMENT,
item_id INTEGER,
bidder TEXT,
amount REAL,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
)
""")
conn.commit()
conn.close()
π― This ensures the tables exist when the server starts.
π 2. Start the Socket Server
The server listens for connections and handles JSON requests:
def start_server():
init_db()
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((HOST, PORT))
server.listen()
print(f"[SERVER] Listening on {HOST}:{PORT}")
while True:
conn, addr = server.accept()
threading.Thread(target=handle_client, args=(conn, addr), daemon=True).start()
π‘ Each client connection gets a new thread so multiple users can interact simultaneously.
π 3. Handle Client Requests
When a client sends a JSON command, the server parses it:
data = conn.recv(65536)
request = json.loads(data.decode())
action = request.get("action")
Depending on "action", the server performs:
βοΈ get_auctions
βοΈ place_bid
βοΈ create_auction
βοΈ start_auto_bid
βοΈ and moreβ¦
Each action updates the DB and sends back a JSON response.
πΈ 4. Placing a Bid
The core logic ensures a bid is valid:
if amount < current_bid + min_inc:
return False, "Bid must be at least ..."
UPDATE auctions SET current_bid=?, highest_bidder=? ...
INSERT INTO bids (item_id, bidder, amount) ...
β This ensures bids are incremental and correctly logged.
π€ 5. Auto-Bid Loop
Auto-bidding lets a user set a maximum bid:
def auto_bid_loop(item_id):
while True:
time.sleep(REFRESH_INTERVAL)
if current_bid >= max_bid:
auto_bids[item_id]["active"] = False
return
if highest_bidder != bidder:
new_bid = min(current_bid + min_inc, max_bid)
π§ This thread checks periodically and automatically increases the bid.
π₯οΈ 6. Build the Admin GUI
Admins can create auctions from the desktop app using Tkinter + ttkbootstrap:
payload = {
"name": item_name.get(),
"starting_bid": float(starting_bid.get()),
"min_increment": float(min_increment.get()),
...
}
send_request({"action": "create_auction", "payload": payload})
The GUI collects form data and sends it to the server with "create_auction".
π 7. Live Auction Display
The Admin panel also displays running auctions:
res = send_request({"action": "get_auctions"})
items = sorted(res["auctions"], ...)
Each auction line shows:
βοΈ Current bid
βοΈ Highest bidder
βοΈ Start & end times
βοΈ Buttons to close, make public/private, delete
π€ 8. Bidder App
The Bidder GUI shows only public auctions:
if not item.get("public"):
continue
Bidders can enter:
π Item ID
π° Bid amount
send_request({"action": "place_bid", ...})
π When an auction closes, bidders are notified if they won.
π οΈ 9. Refresh Loop
Both GUIs use a background thread to refresh every few seconds:
while True:
time.sleep(REFRESH_INTERVAL)
res = send_request({"action": "get_auctions"})
This makes the app feel real-time even over sockets.
π Final Thoughts
You now understand how:
π A socket server accepts JSON commands
π Clients interact via simple GUI forms
π Auctions and bids update live
π Auto-bidding is handled in a loop
This project is a great starting point for real-time apps using Python networking and desktop UI.





Top comments (0)