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

fix listener #291

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions tests/listen.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

import sys
import socket
Expand Down Expand Up @@ -45,51 +45,51 @@

print('[+] Listening for connections on {0}:{1}'.format(host, port))

data = ''
received_exit = False
while not received_exit:
data = b''
exit = False
while not exit:
conn, address = s.accept()
print('[+] Connection from {0}'.format(address))
while 1:
try:
readable, writable, exceptional = \
select.select([conn], [conn], [], timeout)
except select.error:
print('[+] Exception. Closing connection from {0}'.format(address))
readable, writeable, in_error = \
select.select([conn, ], [conn, ], [], timeout)
except (select.error, socket.error):
print('[+] Closing connection from {0}'.format(address))
conn.shutdown(2)
conn.close()
break
if readable:
data = conn.recv(1024)
if data.endswith(u'\n'):
if data.startswith(u'status 3'):
conn.send(status)
data = ''
elif data.startswith(u'state'):
conn.send(state)
data = ''
elif data.startswith(u'version'):
conn.send(version)
data = ''
elif data.startswith(u'load-stats'):
conn.send(stats)
data = ''
elif data.startswith(u'quit'):
if data.decode().endswith('\n'):
if data.decode().startswith('status 3'):
conn.send(bytes(status, 'utf-8'))
data = b''
elif data.decode().startswith('state'):
conn.send(bytes(state, 'utf-8'))
data = b''
elif data.decode().startswith('version'):
print('got vesi')
conn.send(bytes(version, 'utf-8'))
data = b''
elif data.decode().startswith('load-stats'):
conn.send(bytes(stats, 'utf-8'))
data = b''
elif data.decode().startswith('quit'):
print('[+] Closing connection from {0}'.format(address))
conn.shutdown(2)
conn.close()
data = ''
data = b''
break
elif data.startswith(u'exit'):
elif data.decode().startswith('exit'):
print('[+] Closing connection from {0}'.format(address))
conn.shutdown(2)
conn.close()
s.close()
received_exit = True
exit = True
break
else:
pass
elif readable and writable:
elif readable and writeable:
print('[+] Closing connection from {0}'.format(address))
conn.shutdown(2)
conn.close()
Expand Down
Loading