Skip to content

Instantly share code, notes, and snippets.

@nickedes
Created April 20, 2015 20:07
Show Gist options
  • Save nickedes/6c8efacc9b94e0d43600 to your computer and use it in GitHub Desktop.
Save nickedes/6c8efacc9b94e0d43600 to your computer and use it in GitHub Desktop.
socket
# !/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)
# !/usr/bin/python # This is server.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.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
msg = raw_input("enter plaintext:")
c.send(msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment