Last active
September 30, 2015 20:41
-
-
Save divyanshu013/3d4fe7266deef6f57607 to your computer and use it in GitHub Desktop.
A simple server-client application in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python # This is client.py file | |
import socket # Import socket module | |
s = socket.socket() # Create a socket object | |
host = socket.gethostname() # Get local machine name | |
port = 12345 # Reserve a port for your service. | |
s.connect((host, port)) | |
print s.recv(1024) | |
s.close() # Close the socket when done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python # This is server.py file | |
import socket # Import socket module | |
server = socket.socket() # Create a socket object | |
host = socket.gethostname() # Get local machine name | |
port = 12345 # Reserve a port for your service. | |
server.bind((host, port)) # Bind to the port | |
server.listen(5) # Now wait for client connection. | |
while True: | |
client, addr = server.accept() # Establish connection with client. | |
print 'Got connection from', addr | |
client.send('Connection closed') | |
client.close() # Close the connection |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment