From Anonymous, 1 Year ago, written in Python.
Embed
  1. import socket
  2. import time
  3. import random
  4. server_socket = socket.socket()
  5. server_socket.bind(('0.0.0.0',9829))
  6. server_socket.listen(1)  # open socket and open line for one client
  7. (client_socket, client_address) = server_socket.accept()
  8. client_name = client_socket.recv(1024)
  9. if client_name == "time":  # this will check the client request and give back what he wanted
  10. client_socket.send(time.asctime(time.localtime()))
  11. elif client_name == "server name":
  12. client_socket.send("this is not your business!")
  13. elif client_name == "rand":
  14. client_socket.send(random.randint(0, 10))
  15. elif client_name == "exit":
  16. client_socket.close()
  17. server_socket.close()
  18. client_socket.close()
  19. server_socket.close()