1
1
'''
2
- WARNING: under Linux, socket.sendfile is overridden!!!
2
+ A socket that supports object transmission.
3
3
'''
4
4
import socket
5
5
import pickle
6
6
from io import BytesIO
7
7
import sys
8
8
__all__ = ['PickleSocket' , 'RemoteClosedUnexpectedly' ]
9
9
10
- if 'sendfile' not in dir (socket .socket ):
11
- # Android
12
- def fakeSendfile (self , file , offset = 0 , count = None ):
13
- start = file .tell ()
14
- if offset != 0 :
15
- file .seek (start + offset )
16
- read = file .read (4096 )
17
- while read != b'' :
18
- self .sendall (read )
19
- read = file .read (4096 )
20
- return file .tell () - start - offset
21
- socket .socket .sendfile = fakeSendfile
22
-
23
10
class PickleSocket ():
24
11
def __init__ (self ,upon_this_socket = None ):
25
12
if upon_this_socket is None :
@@ -40,13 +27,11 @@ def shakeHands(self,banner='This is a pickleSocket by Daniel Chin. ',echo=True):
40
27
input ('Enter to exit...' )
41
28
sys .exit (1 )
42
29
43
- def bind (self ,address ,AB = False ,dorm = False ,local = False ):
44
- '''if AB or dorm is True, address is no longer a tuple, but a port int.'''
45
- if AB :
46
- self .socket .bind (('10.209.1.45' ,address ))
47
- elif dorm :
48
- self .socket .bind (('10.209.23.186' ,address ))
49
- elif local :
30
+ def bind (self ,address ,local = False ):
31
+ '''
32
+ if `local` is True, address is no longer a tuple, but a port int.
33
+ '''
34
+ if local :
50
35
self .socket .bind (('127.0.0.1' ,address ))
51
36
else :
52
37
self .socket .bind (address )
0 commit comments