Skip to content

Instantly share code, notes, and snippets.

@jonaslsaa
Created December 5, 2014 08:14
Show Gist options
  • Save jonaslsaa/326116f1d0b58c0ea4c1 to your computer and use it in GitHub Desktop.
Save jonaslsaa/326116f1d0b58c0ea4c1 to your computer and use it in GitHub Desktop.
Improved One way message redux using sockets.
import socket # Import socket module
host = raw_input("Host IP: ") # Get local machine name
port = 12345 # Reserve a port for your service.
while True:
s = socket.socket() # Create a socket object
s.connect((host, port))
print s.recv(1024)
s.close # Close the socket when done
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
print("Your IP is: " + str(host))
s.listen(5) # Now wait for client connection.
while True:
c, addr = s.accept() # Establish connection with client.
print 'Got connection from', addr
x = raw_input("Send: ")
print("\n"*25)
print("Your IP is: " + str(host))
c.send(x)
c.close() # Close the connection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment