コード例 #1
0
	def connect(self):
		try:
			#print("Remote addr: \n" + self.remote_addr[0] + "\n" + str(self.remote_addr[1]))
			#print("Bind addr: \n" + self.bind_addr[0] + "\n" + str(self.bind_addr[1]))			
			#self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
			#self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
			#self.sock.bind(self.bind_addr)
			#sfutils.logstr("socket bind to " + str(self.bind_addr))
			#self.sock.connect(self.remote_addr)
			self.sock = socket.create_connection(self.remote_addr, 10, self.bind_addr)
			sfutils.logstr("connected to" + str(self.remote_addr))
		except socket.error as e:
			print(e)
			sys.exit(1)
コード例 #2
0
def handler(clientsocket, clientaddr):
    sfutils.logstr("Accepted connection")
    sfutils.logstr(str(clientsocket))

    while 1:
        try:
            data = None
            data = clientsocket.recv(1024)
            if not data:
                break
        except Exception as e:
            print(e)
        finally:
            if data is None:
                break
            else:
                data = data.decode('utf-8')
                data = data.replace('\n', '')
                sfutils.logstrtabdelim(data)

    sfutils.logstr("shutting down socket")
    sfutils.logstr(str(clientsocket))
    clientsocket.shutdown(socket.SHUT_RDWR)
    clientsocket.close()
コード例 #3
0
def handler(clientsocket, clientaddr):
    sfutils.logstr("Accepted connection")
    sfutils.logstr(str(clientsocket))

    while 1:
        try:
            data = None
            data = clientsocket.recv(1024)
            if not data:
                break
        except Exception as e:
            print(e)
        finally:
            if data is None:
                break
            else:
                data = data.decode("utf-8")
                data = data.replace("\n", "")
                sfutils.logstrtabdelim(data)

    sfutils.logstr("shutting down socket")
    sfutils.logstr(str(clientsocket))
    clientsocket.shutdown(socket.SHUT_RDWR)
    clientsocket.close()
コード例 #4
0
	def send(self, data):
		try:
			self.sock.sendall(bytes(data + "\n", 'UTF-8'))
			sfutils.logstr(msg=data, screen=False)
			# Receive data from the server and shut down
			#received = self.sock.recv(1024)			
		except socket.error as ex:
			sfutils.logstr("socket error")
			logging.info(ex)	
			print(ex)
			self.sock.close()
			self.sock = None
			sfutils.logstr("reconnecting")
			self.connect()

		except socket.timeout as ex:
			logging.info("socket connection timer expired")
			logging.info(ex)	
コード例 #5
0
	RUN_RT = sfc.RUN_RT
	SIM_RT_FACTOR = sfc.SIM_RT_FACTOR 	
	NUM_PARTS = sfc.NUM_PARTS
	NUM_MACHINES = sfc.NUM_MACHINES
	NUM_STATIONS = sfc.NUM_STATIONS
	WORKTIME = sfc.WORKTIME
	T_INTER = sfc.T_INTER
	
	# remote server address
	REMOTE_ADDR = sfc.server_addr
	
	# configure the logging utility for the plant process
	logging.basicConfig(filename='sf_plant.log', level=logging.INFO)
	sfutils.logheader()

	# Create an environment and start the setup process
	if RUN_RT:
		sfutils.logstr("attempting to run in real-time with wall clock")
		env = simpy.rt.RealtimeEnvironment(initial_time=0, factor=SIM_RT_FACTOR, strict=False)
	else:
		env = simpy.Environment()

	# create the factory
	factory = Factory(NUM_PARTS, NUM_MACHINES, NUM_STATIONS, WORKTIME, T_INTER, REMOTE_ADDR)
	factory.run(env)

	# Execute simulation
	env.run()