For a friend.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

server.py 677B

1234567891011121314151617181920212223
  1. #!/usr/bin/env python3
  2. import socket # Import the lib
  3. TCP_IP = '127.0.0.1' # Set the listen address
  4. TCP_PORT = 5005 # set the port
  5. BUFFER_SIZE = 20 # Normally 1024, but we want fast response
  6. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Create the socket
  7. s.bind((TCP_IP, TCP_PORT))
  8. s.listen(1)
  9. conn, addr = s.accept() # Accept every connection
  10. print ('Connection address:', addr) # display connection detail.
  11. while 1:
  12. data = conn.recv(BUFFER_SIZE)
  13. print ("received data:", data) # Print what you recive.
  14. conn.send(data) # echo
  15. if (data == b"exit"): # Exit the program once you recieve "exit".
  16. break
  17. conn.close() #Close the connection.