Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

import socket

import pygame

# Initialize Pygame

pygame.init()

# Create a server socket and bind to a port

server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

server_socket.bind(('0.0.0.0', 1234))

server_socket.listen(5)

# Set the display mode and caption for the game window

size = (700, 500)

screen = pygame.display.set_mode(size)

pygame.display.set_caption("My Game")

# Create a list to store the connected clients

clients = []

# Create a game loop that will run until the player quits the game

running = True

while running:

for event in pygame.event.get():

if event.type == pygame.QUIT:

running = False

# Check for incoming connections

(client_socket, client_address) = server_socket.accept()

client_socket.setblocking(0)

clients.append(client_socket)
# Update the game state and render the game

for client_socket in clients:

client_socket.send("update")

screen.fill((0, 0, 0))

pygame.display.flip()

# Clean up resources before the program exits

server_socket.close()

pygame.quit()

You might also like