Skip to content

Instantly share code, notes, and snippets.

@daryltucker
Created November 21, 2014 22:04
Show Gist options
  • Save daryltucker/9b1058e76de616c9bb88 to your computer and use it in GitHub Desktop.
Save daryltucker/9b1058e76de616c9bb88 to your computer and use it in GitHub Desktop.
Receive all data in socket buffer (python)
import socket
import ssl
'''
Receive all data in socket buffer, while preventing locking/blocking.
'''
sockx = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock = ssl.wrap_socket(sockx)
# Listening
try:
text = ''
chunk = ''
while True:
chunk += sock.recv()
if not chunk:
# Unreliable
break
else:
text += chunk
except Exception:
if text:
pass
else:
return False
print text
@prashanthirave
Copy link

according to this I get error
SSLError:[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:661)

@jadrezz
Copy link

jadrezz commented Apr 17, 2024

One of the solutions is using unlocked sockets and selectors. I tried to resolver this problem one day, here's my hub
https://github.com/jdrzz/Unblocking-sockets-echo-server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment