Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to create A Simple Server in python

    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 817
    Comment on it

    In python simple server is Internet servers, we use the socket function available in socket module to create a socket object. After then a socket object is used to call other functions to setup a socket server. after this call bind(hostname, port) function to specify a port for your service on the given host.
    use this code given below:

    import socket               # Import socket module
    
    s = socket.socket()         # Create a socket object
    host = socket.gethostname() # Get local machine name
    port = 192168116              # Reserve a port for your service.
    s.bind((host, port))        # Bind to the port
    
    s.listen(5)                 # Now wait for client connection.
    while True:
       c, addr = s.accept()     # Establish connection with client.
       print 'Got connection from', addr
       c.send('Thank you for connecting')
       c.close()                # Close the connection
    

 1 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: