document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #!/usr/bin/python
  2.  
  3. import socket
  4. import sys
  5.  
  6. #Try to get the nickname from the execution arguments
  7. try:
  8.     nick = sys.argv[1]
  9. #If it is not specified, make it "Guest"
  10. except IndexError:
  11.     nick = "Guest"
  12. #Try to get the port from the execution arguments
  13. try:
  14.     port = int(sys.argv[2])
  15. #If it is not specified make it 9999
  16. except IndexError:
  17.     port = 9999
  18.  
  19. #Create a socket and connect it with (IP, port)
  20. #In this case "the IP" is localhost
  21. s = socket.socket()
  22. s.connect(("localhost",  port))
  23.  
  24. print "\\t\\t.::Client-Server Mergesort::."
  25. print "\\t\\t1- Please use the syntax: X-X-X-X-X"
  26. print "\\t\\t(Where the X\'s are the numbers to order)"
  27. print "\\t\\t2- Type exit to finish the program"
  28.  
  29. #Main loop
  30. while  True:
  31.     #Get the list as an input and send it to the server
  32.     list_str = raw_input("%s -> List to Sort: "%nick)
  33.     s.send(list_str)
  34.     #If the string is exit, finish the client program
  35.     if list_str  == "exit":
  36.         break
  37.     #Wait until the server sorts the list
  38.     sorted_list = s.recv(1024)
  39.     #If the result of the sorted list is false
  40.     #the input had invalid characters so show a message
  41.     if sorted_list == "False":
  42.         print "Invalid Input. Try Again"
  43.     #If the input  was correct, print the results
  44.     else:
  45.         print "\\tSorted List: %s"%(sorted_list)
  46. print  "Exit"
  47. #Close the socket
  48. s.close()
');