Browse Source

use sendall()

1.4
clowwindy 12 years ago
parent
commit
65444c5b06
  1. 4
      README.md
  2. 10
      local.py
  3. 9
      server.py

4
README.md

@ -40,6 +40,10 @@ You can use args to override settings from `config.json`.
You may want to install gevent for better performance.
$ apt-get install python-gevent
Or:
$ sudo easy_install gevent
troubleshooting

10
local.py

@ -52,7 +52,7 @@ def get_table(key):
class ThreadingTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
pass
allow_reuse_address = True
class Socks5Server(SocketServer.StreamRequestHandler):
@ -65,14 +65,13 @@ class Socks5Server(SocketServer.StreamRequestHandler):
data = sock.recv(4096)
if data <= 0:
break
if remote.send(self.encrypt(data)) <= 0:
break
remote.sendall(self.encrypt(data))
if remote in r:
data = remote.recv(4096)
if data <= 0:
break
if sock.send(self.decrypt(data)) <= 0:
break
sock.sendall(self.decrypt(data))
finally:
sock.close()
remote.close()
@ -162,7 +161,6 @@ if __name__ == '__main__':
decrypt_table = string.maketrans(encrypt_table, string.maketrans('', ''))
try:
server = ThreadingTCPServer(('', PORT), Socks5Server)
server.allow_reuse_address = True
logging.info("starting server at port %d ..." % PORT)
server.serve_forever()
except socket.error, e:

9
server.py

@ -52,7 +52,7 @@ def get_table(key):
class ThreadingTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
pass
allow_reuse_address = True
class Socks5Server(SocketServer.StreamRequestHandler):
@ -65,14 +65,12 @@ class Socks5Server(SocketServer.StreamRequestHandler):
data = sock.recv(4096)
if data <= 0:
break
if remote.send(self.decrypt(data)) <= 0:
break
remote.sendall(self.decrypt(data))
if remote in r:
data = remote.recv(4096)
if data <= 0:
break
if sock.send(self.encrypt(data)) <= 0:
break
sock.send(self.encrypt(data))
finally:
sock.close()
remote.close()
@ -137,7 +135,6 @@ if __name__ == '__main__':
ThreadingTCPServer.address_family = socket.AF_INET6
try:
server = ThreadingTCPServer(('', PORT), Socks5Server)
server.allow_reuse_address = True
logging.info("starting server at port %d ..." % PORT)
server.serve_forever()
except socket.error, e:

Loading…
Cancel
Save