Skip to content

PYTHON SOCKET SERVER BROKEN PIP ON EV3DEV #1177

@Negociation

Description

@Negociation

Hi , everyone i need a little help , i'm trying to use socket TCP to control my Robot using my Tablet... , but i having some issues with broken pip on EV3...

MY ARQUITECTURE:

BrickPI EV3DEV Windows Tablet Android Device
Client <---> Server <---> Client

My Server :
`

class Servidor:
	sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	connections = []
	def __init__(self):
		#Dados da Conexao [ IP GERAL | PORTA ]
		self.sock.bind(('0.0.0.0', 8000 ))
		self.sock.listen(10)
		
	def handler(self, c,a):
		while True:
			data = c.recv(1024)
			for connection in self.connections:
				connection.send(data)				
				if not data:
					break;
	def run(self):
		while True:
			c,a = self.sock.accept()
			cThread = threading.Thread(target=self.handler, args=(c,a))
			cThread.start()
			self.connections.append(c)
			print(self.connections)

Meu_Servidor = Servidor()
Meu_Servidor.run()

My Client on EV3:


#Thread para Servidor ( Cliente )
class Thread_Server (threading.Thread):
	sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	def __init__(self):
		threading.Thread.__init__(self)
	def sendMsg(self):
		while True:
			msg = 'teste'
			self.sock.send(bytes(msg, 'utf-8'))
			sleep(1)
	
	def run(self):
		iThread = threading.Thread(target=self.sendMsg)
		iThread.start()
		try:
        		self.sock.connect(('192.168.16.110', 8000))
		except:
			print("Nao consegui conectar no servidor , Abortar o Programa")
		while True:
			data = self.sock.recv(1024)
			if not data:
				print ("Disconnected")
				break;
			print(str(data, 'utf-8'))

#Inicializacao da Thread do Servidor
Server = Thread_Server()
Server.start()


I tested the same code on my machine using localhost and working fine...

MY ERROR APPEARS ON SENDMSG FUNCTION:

Inicializando o Sistema de Captura de Dados (SCD) 3.2.1

Exception in thread Thread-5:
Traceback (most recent call last):
File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/usr/lib/python3.5/threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "./SCD.py", line 386, in sendMsg
self.sock.send(bytes(msg, 'utf-8'))
BrokenPipeError: [Errno 32] Broken pipe

^CTraceback (most recent call last):
File "./SCD.py", line 465, in
sleep(1)
KeyboardInterrupt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions