Exemple #1
0
	def _conexions(self):

		print('Esperando conexiones ...')
		while 1:
			try:
				if len(self._clients) < 10:
					conn,addr = self._socket.accept()
					conn.setblocking(False)
					
					print(f'Conectado con {addr}')

					"""
					Numero del cliente
					"""

					conn.send(_pack(self._current_player))

					client = (conn,[addr,self._current_player])

					self._current_player +=1
					if self._current_player == 4:
						self._current_player = 0

					self._clients.append(client)
					print(f'Numero de conexiones: {len(self._clients)}' )
				else:
					break
			except:
				pass
Exemple #2
0
 def _messages_client(self, data, client):
     data_pack = _pack(data)
     for conn, addr in self._clients:
         try:
             if conn != client:
                 conn.send(data_pack)
         except:
             if client in self._clients:
                 self._clients.remove(client)
Exemple #3
0
	def _messages_client(self,data,client):
		
		data_pack = _pack(data)				
		for conn,addr in self._clients:
			try:
				if conn != client:
					conn.send(data_pack)
			except:
				#print(f"Error con el cliente {client[0]}")

				if client in self._clients:
					#print(f"¡El cliente {client[0]} Ha sido eliminado!")
					self._clients.remove(client)
Exemple #4
0
    def _send(self, player):

        try:
            player = _pack(player)
            self._socket.send(player)

            data_server = self._socket.recv(BUFFER_SIZE)
            data = _unpack(data_server)

            if data:
                self._data[data._num_player] = data

        except socket.error as e:
            print(e)
            print("Conexión perdida con el servidor.")
            self._socket.close()