Python- run socket script on the remote linux host
Question: I have uploaded the server script to the public directory on the server
machine. Then I try to connect to the server by a client, but I am not being
connected. Here is my code snippets:

    
    
    # Echo client program
    import socket
    
    HOST = 'www.dotpy.ir/server.py'    # The remote host
    PORT = 50007              # The same port as used by the server
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((HOST, PORT))
    s.send('Hello, world')
    data = s.recv(1024)
    s.close()
    print 'Received', repr(data)
    

server:

    
    
    # Echo server program
    import socket 
    HOST = ''                 # Symbolic name meaning all available interfaces
    PORT = 50007              # Arbitrary non-privileged port
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind((HOST, PORT))
    s.listen(1)
    conn, addr = s.accept()
    print 'Connected by', addr
    while 1:
        data = conn.recv(1024)
        if not data: break
        conn.send(data)
    conn.close()
    


Answer: These scripts seem to work well.

However, the script at the server must be run on the server for this to work.
It's not enough for it to be uploaded to the public file area. What access do
you have to the servers? Can you have scripts running on them?

If you succeed in running the script, then you will have to change the client
script from:

    
    
    HOST = 'www.dotpy.ir/server.py'    # The remote host
    

to

    
    
    HOST = 'www.dotpy.ir'    # The remote host
    

The reason is that you will connect to the host itself. There the script will
be running, listening to any inbound connections on the port specified. You
can't conect to a specific script.

Good luck!

