Browse Source

add gevent

1.4
clowwindy 12 years ago
parent
commit
12173a66d1
  1. 4
      README.md
  2. 13
      local.py
  3. 13
      server.py

4
README.md

@ -13,6 +13,7 @@ First, make sure you have Python 2.6 or 2.7.
$ python --version
Python 2.6.8
Then edit `config.json`, change the following values:
server your server ip or hostname
@ -37,6 +38,9 @@ You can use args to override settings from `config.json`.
python local.py -s server_name -p server_port -l local_port -k password
python server.py -p server_port -k password
You may want to install gevent for better performance.
$ sudo easy_install gevent
troubleshooting
---------------

13
local.py

@ -20,6 +20,14 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import sys
try:
import gevent, gevent.monkey
gevent.monkey.patch_all(dns=gevent.version_info[0]>=1)
except ImportError:
gevent = None
print >>sys.stderr, 'warning: gevent not found, using threading instead'
import socket
import select
@ -27,7 +35,6 @@ import SocketServer
import struct
import string
import hashlib
import sys
import os
import json
import logging
@ -58,13 +65,13 @@ class Socks5Server(SocketServer.StreamRequestHandler):
data = sock.recv(4096)
if data <= 0:
break
if remote.sendall(self.encrypt(data)) is not None:
if remote.send(self.encrypt(data)) <= 0:
break
if remote in r:
data = remote.recv(4096)
if data <= 0:
break
if sock.sendall(self.decrypt(data)) is not None:
if sock.send(self.decrypt(data)) <= 0:
break
finally:
sock.close()

13
server.py

@ -20,6 +20,14 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import sys
try:
import gevent, gevent.monkey
gevent.monkey.patch_all(dns=gevent.version_info[0]>=1)
except ImportError:
gevent = None
print >>sys.stderr, 'warning: gevent not found, using threading instead'
import socket
import select
@ -27,7 +35,6 @@ import SocketServer
import struct
import string
import hashlib
import sys
import os
import json
import logging
@ -58,13 +65,13 @@ class Socks5Server(SocketServer.StreamRequestHandler):
data = sock.recv(4096)
if data <= 0:
break
if remote.sendall(self.decrypt(data)) is not None:
if remote.send(self.decrypt(data)) <= 0:
break
if remote in r:
data = remote.recv(4096)
if data <= 0:
break
if sock.sendall(self.encrypt(data)) is not None:
if sock.send(self.encrypt(data)) <= 0:
break
finally:
sock.close()

Loading…
Cancel
Save