Created
May 25, 2011 21:10
-
-
Save Lothiraldan/991995 to your computer and use it in GitHub Desktop.
Client socketServer
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 sys | |
| HOST, PORT = "localhost", 9999 | |
| data = str(sys.argv[1]) | |
| # Create a socket (SOCK_STREAM means a TCP socket) | |
| sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| # Connect to server and send data | |
| sock.connect((HOST, PORT)) | |
| sock.send(data + "\n") | |
| # Receive data from the server and shut down | |
| received = sock.recv(1024) | |
| print "Sent: %s" % data | |
| print "Received: %s" % received | |
| data = str(sys.argv[2]) | |
| sock.send(data + "\n") | |
| received = sock.recv(1024) | |
| print "Sent2: %s" % data | |
| print "Received2: %s" % received | |
| sock.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment