Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import socket
- import threading
- SIZE =4
- class client(threading.Thread):
- def __init__(self,c):
- threading.Thread.__init__(self)
- self.conn = c
- self.stopIt = False
- def mrecv(self):
- data = self.conn.recv(SIZE)
- if data != '':
- self.conn.send('OK')
- return self.conn.recv(int(data))
- def run(self):
- while not self.stopIt:
- msg = self.mrecv()
- if msg != None:
- print 'received-> ',msg
- print "estiblishing soc1"
- soc1 = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
- print "connecting soc1"
- soc1.connect(('216.99.220.219',12345))
- print "sending on soc1"
- soc1.send('WILL SEND') # telling server we will send data from here
- print "estiblishing soc2"
- soc2 = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
- print "connecting soc2"
- soc2.connect(('216.99.220.219',12345))
- print "sending soc2"
- soc2.send('WILL RECV') # telling server we will recieve data from here
- def msend(conn,msg):
- print "sending " + msg
- if len(msg)<=999 and len(msg)>0:
- conn.send(str(len(msg)))
- if conn.recv(2) == 'OK':
- conn.send(msg)
- else:
- conn.send(str(999))
- if conn.recv(2) == 'OK':
- conn.send(msg[:999])
- msend(conn,msg[1000:]) # calling recursive
- thr = client(soc2)
- thr.start()
- try:
- while 1:
- msend(soc1,raw_input("Say something rude: "))
- except:
- print 'closing'
- thr.stopIt=True
- msend(soc1,'bye!!') # for stoping the thread
- thr.conn.close()
- soc1.close()
- soc2.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement