Commit a132e579 by Phillip Seo

Upload New File

parent 5782422f
Showing with 30 additions and 0 deletions
import socket
import sys
#using TCP socket
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#accepting server port and only command-line argument
port = int(sys.argv[1])
serversocket.bind(('localhost', port))
serversocket.listen(5)
#infinite loop to wait for incoming connections from client
while True:
#accept incoming connection
conn, client = serversocket.accept()
#read in text from connection
text = conn.recv(100)
#print text to STDOUT
print(text.decode())
#send text back to client
conn.sendall(text)
#close connection
conn.close()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment