Hello,
I have used Multi-Mechanize for testing a server by establishing TCP Sockets (Establishing large # of sockets using the tool, send some message and test its stability)
Note: Change the variable 'no_of_sockets' to adhere to your testing needs. The # of sockets can be controlled by this variable and by #of threads in the config file.
In the below code 'no_of_sockets' is set to 10. And my config file has 2 user groups each with 5 threads. Hence, total # of sockets =2*5*10=100
Following is the sample code:#Python Script to establish TCP sockets and send data
import socket
import time
sock_array=[]
class Transaction(object):
def run(self):
#Initialise Variables
host = '
XXX.XXX.com'
port = 1234
src = ''
no_of_sockets = 10
message="XXX"
#Create Socket
while no_of_sockets !=0:
try:
s = socket.create_connection((host,port),10,(src,0))
except Exception, e:
print "Exception: "+str(e)
sock_array.append(s)
print sock_array
no_of_sockets-=1
#Send Message
remote_ip = socket.gethostbyname(host)
print 'Socket Connected to ' + host + ' on ip ' + remote_ip
s.sendall(message)
print 'Message send successfully'
reply = s.recv(4096)
if reply=="":
print "no response"
print reply
time.sleep(120)
if __name__ == '__main__':
trans= Transaction()
trans.run()
Hope this helps.
Thanks!