Created
December 5, 2014 08:14
-
-
Save jonaslsaa/326116f1d0b58c0ea4c1 to your computer and use it in GitHub Desktop.
Improved One way message redux using sockets.
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
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 |
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
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