<commit_before>require 'rubygems'
require 'socket'

class TCP

	attr_accessor :clients

	def initialize(main_class)
		@parent = main_class
		@clients = Array.new
		@server
	end
	
	def connectServer
		@server = TCPServer.open(@parent.server_config['server_port'])
		if @server != nil
			@parent.logger.info('Successfully connected to the Game server')
		else
			@parent.logger.info('Failed to connect to the Game server')
		end
	end
	
	def listenServer
		Thread.new(@server.accept) do |connection|
			@parent.logger.info("Accepting connection from #{connection.peeraddr[2]}")
			client = CPUser.new(@parent, connection)
			@clients << client
			begin
				while true
				data = connection.recv(65536)
				if data.empty? == true
					client.removePlayerFromRoom
					self.handleRemoveClient(connection)
					break
				end
				self.handleIncomingData(data, client)	
				connection.flush
			end
			rescue Exception => e
				@parent.logger.error("#{e} (#{e.class}) - #{e.backtrace.join("\n\t")}")
			ensure
				client.saveClientInformation
				client.removePlayerFromRoom
				self.handleRemoveClient(connection)<commit_msg>Update TCP.rb<commit_after>require 'rubygems'
require 'socket'

class TCP

	attr_accessor :clients

	def initialize(main_class)
		@parent = main_class
		@clients = Array.new
		@server
	end
	
	def connectServer
		@server = TCPServer.open(@parent.server_config['server_port'])
		if @server != nil
			@parent.logger.info('Successfully connected to the Game server')
		else
			@parent.logger.info('Failed to connect to the Game server')
		end
	end
	
	def listenServer
		Thread.new(@server.accept) do |connection|
			@parent.logger.info("Accepting connection from #{connection.peeraddr[2]}")
			client = CPUser.new(@parent, connection)
			@clients << client
			begin
				while true
				data = connection.recv(65536)
				if data.empty? == true
					client.removePlayerFromRoom
					self.handleRemoveClient(connection)
					break
				end
				self.handleIncomingData(data, client)	
				connection.flush
			end
			rescue Exception => e
				@parent.logger.error("#{e} (#{e.class}) - #{e.backtrace.join("\n\t")}")
			ensure
				client.removePlayerFromRoom
				self.handleRemoveClient(connection)
{'fraction_non_alphanumeric': 0.11358473421172194, 'fraction_numerical': 0.005452067242162653, 'mean_word_length': 3.8183807439824946, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4641372', 'n_tokens_mistral': 830, 'n_tokens_neox': 681, 'n_words': 157}