Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opening a saved project in Scratch breaks the handler #3

Open
tompreston opened this issue Feb 26, 2014 · 4 comments
Open

Opening a saved project in Scratch breaks the handler #3

tompreston opened this issue Feb 26, 2014 · 4 comments

Comments

@tompreston
Copy link
Member

When a saved project is opened the socket does not hang and

received something ['']

is printed over and over.

Fix: kill the scratch hander (ctrl+z then kill %%) and restart it.

@tompreston
Copy link
Member Author

Possible fix: check for empty string a couple of times in a row. Close/Open socket. Retry x 5.

@tompreston
Copy link
Member Author

So after opening a project and watching the Scratch Handler restart the Scratch Handler fails to receive data from the Recv-Q (MESH (Scratch) is localhost:42001):

$ netstat -t
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp      187      0 localhost:56121         localhost:42001         ESTABLISHED
tcp        0      0 localhost:42001         localhost:56121         ESTABLISHED

Same results after commenting out line 98. It looks like an issue with the way I use the socket to talk to Scratch. Can anyone shed some light on this?

@mikajones
Copy link
Contributor

It appears that the when a saved project is opened there is a decode error with the first line

Just reading the socket with
while True:
data = s.recv(BUFFER_SIZE).decode('utf-8')
print (data)

Produces a decode error
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 3: invalid start byte

Without the decode the socket is returning
b'\x00\x00\x00\x80sensor-update "piface-output3" 0 "piface-output4" 1 "piface-output5" 1 "piface-output6" 0 "piface-output7" 0 "piface-output8" 1 '

I am not sure how to handle this yet

@mikajones
Copy link
Contributor

If you change the read socket line to the line bellow it will work when you open a saved project

data = scratch_socket.recv(BUFFER_SIZE).decode('utf-8','replace')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants