Python socket multiple calls using Eventlet
Question: I need to call a socker server multiple times and print its output.

Here is my below code:-

server.py

    
    
    import socket
    
    s = socket.socket()
    
    host = socket.gethostname()
    
    port = 1234
    
    s.bind((host, port))
    
    s.listen(5)
    
    print "Server started"
    while True:
        c, addr = s.accept()
        print('Got connection from', addr)
        #sprint('Received message == ',c.recv(50))
        s = c.recv(50)[::-1]
        c.send(s)
        c.close()
    

client.py

    
    
        import socket
    from time import sleep
    import eventlet
    
    def socket_client():
        s = socket.socket()
    
        host = socket.gethostname()
    
        port = 1234
    
        s.connect((host, port))
    
        print "Sending data"
        s.sendall("Hello!! How are you")
        print(s.recv(1024))
    
    #socket_client()
    pile = eventlet.GreenPile()
    
    for x in range(10):
            print 'new process started'
            pile.spawn(socket_client())
            print 'new process started over'
    
    print 'over'
    

I use a python eventlet to call the socket_client() 10 times but its not
returning the correct result..


Answer: You're overriding variable with socket by string received from socket:

    
    
    s = socket.socket()
    ...
    s = c.recv(50)[::-1]
    

Pick different variable name for the second case.

