Beispiel #1
0
def generic_consend_test(server, port):
    s = socket()
    data = Buffer("hello world")
    s.connect((server, port))
    data.make_buffer_sendable()
    s.send(data.get_buf())
    s.close()
Beispiel #2
0
 def recv_traffic(self):
     print "Receiving client: ",str(self.client.getpeername())
     current_length = 0
     data_buf = Buffer()
     while self.listen and self.client:
         try:
             self.conn_lock.acquire()
             #print "Looping...."
             # will read the initial packet
             if current_length > 0:
                 t = self.client.recv(current_length)
                 current_length -= len(t)
                 data_buf.append(t)
             elif current_length == 0:
                 # clear buffer and wait
                 # for new pkt
                 #print "Data buffer was reset, recv'ing a new buf"
                 data_buf.append(self.client.recv(4))
                 current_length = data_buf.read_int() - 4
                 print "Recieved the current length %x"%(current_length+4)
             if current_length == 0 and len(data_buf) > 0:
                 print "Handling the following pkt: %s"%(repr(data_buf.get_buf()))
                 self.handle_recv(data_buf)
                 data_buf = Buffer()
             self.conn_lock.release()
         except timeout:
             if self.conn_lock.locked():
                 self.conn_lock.release()
             print "Timeout occured on the client"
             pass
         except Exception, e:
             if self.conn_lock.locked():
                 self.conn_lock.release()
             if str(sys.exc_info()[1]).find("Errno 10035") > -1:
                 pass
             else:
                 print "Exception Type: %s"%(str(sys.exc_info()[0]))
                 print "Exception Message: %s"%(str(sys.exc_info()[1]))
                 raise e
Beispiel #3
0
def generic_interact_test(server, port):
    s = socket()
    data = Buffer("hello there\n")
    data.make_buffer_sendable()
    print hex(len(data.get_buf())), hex(data.read_int()),data.get_buf()
    s.connect((server, port))
    s.send(data.get_buf())
    data.reset()
    data.append("Do you have and Grey Poupon?\n")
    data.make_buffer_sendable()
    print hex(len(data.get_buf())), hex(data.read_int()),data.get_buf()
    s.send(data.get_buf())
    buf = s.recv(65535)
    print buf
    bufs = input("Enter a response")
    s.send(bufs)
    s.close()