pygame exe program wont connect to server

Viewed 104

so i made a game on pygame which is to be played over a LAN. it works fine when i run the server and i create client instances on my own machine. and i even used auto-to-py-exe to make it an executable so i can test it on other computers. The executable worked perfectly fine on my machine as well. But when i would send it and test it on another machine, the program doesnt even try to connect so none of the game information is sent, i dont know if i packaged the exe wrong or something, any help?

server code:

import socket
import pickle
from _thread import *
from game import Game
from player import Player


hostname = socket. gethostname()
local_ip = socket. gethostbyname(hostname)
print(local_ip)

#server = local_ip
port = 5555

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

try:
    s.bind(('', port))
except socket.error as e:
    print(e)

s.listen()
print("Waiting for connection")
idCount = 0

def threaded_client(conn, p, gameId):
    #threaded client stuff
    


while True:
    #accept incoming connections
    conn, addr = s.accept()
    print("Connected to ", addr)

    idCount += 1
    p = 0
    gameId = (idCount -1)//2
    if idCount %2 == 1:
        games[gameId] = Game(gameId)
        print("making game ", gameId)
    else:
        p = 1
        games[gameId].ready()
        

    
    start_new_thread(threaded_client, (conn, p, gameId))

client code:


import pygame
from drawingTools import Tools
from game import Game
from player import Player
from player import Bullet
from sound import Sound
from network import Network


#dimensions
WIDTH = 900
HEIGHT = 500

HIT = pygame.USEREVENT + 1
EXPIRE = pygame.USEREVENT + 2

#create object
t = Tools(WIDTH, HEIGHT)
win = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Game")





def main():
    #game loop
    run = True
    n = Network()
    s = Sound()
    #this is the method that should be connecting to the server and is where i believe the problem 
    is
    #everything else is game stuff, so i dont think i need to include it  
    n.connect()
    p1:Player = n.send("playerinnit")
    
    
    try:
            game: Game = n.send("get")
            
    except:
        print("error")
    
    
    clock = pygame.time.Clock()
    
    print("player ", p1.p)
    ship, r = p1.loadSprite(p1.p)
    
    
    
    s.music()

    while run:
        game stuff logic

network code:

import socket
import pickle

class Network:
    def __init__(self):
        
        self.client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.server = "ip of the machine where the server is"
        self.port = 5555
        self.addr = (self.server, self.port)
        


    def getPlayer(self):
        return None
    #method that should be doing the connecting, works standalone or with a script but not the exe
    def connect(self):
        try:
            self.client.connect(self.addr)
            #return pickle.load(self.client.recv(4090))
        except:
            print("Could not connect")

    def send(self, data):
        try:
            self.client.send(str.encode(data))
            return pickle.loads(self.client.recv(4090))
        except socket.error as e:
            print(e)

    def sendObj(self, data):
        try:
            self.client.send(pickle.dumps(data))
            return pickle.loads(self.client.recv(4090))
        except socket.error as e:
            return []

    def disconnect(self):
        self.client.close()

main file that is now an exe:

from client import main, playAgain
if __name__ == "__main__":
    main()
    playAgain()

i dont know if yall need anything else like everything the auto-to-py-exe packaged, but any help would be appreciated!

0 Answers
Related