Advertisement
Guest User

c.py

a guest
Apr 19th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. import sys
  2. from ex3utils import Client
  3. import time
  4.  
  5.  
  6. class IRCClient(Client):
  7.  
  8. def onMessage(self, socket, message):
  9. print message
  10. # *** process incoming messages here ***
  11. return True
  12.  
  13.  
  14. # Parse the IP address and port you wish to connect to.
  15. ip = sys.argv[1]
  16. port = int(sys.argv[2])
  17. screenName = sys.argv[3]
  18.  
  19. # Create an IRC client.
  20. client = IRCClient()
  21.  
  22. # Start server
  23. client.start(ip, port)
  24.  
  25. # *** register your client here, e.g. ***
  26. client.send('REG %s' % screenName)
  27.  
  28. while client.isRunning():
  29. try:
  30. typedInput = raw_input("> ").strip()
  31. (command, sep, parameter) = typedInput.strip().partition(' ')
  32.  
  33. if (command == 'TO'):
  34. (para, sep, mess) = parameter.strip().partition(' ')
  35. text = para + ' ' + mess
  36. client.send(text)
  37.  
  38. elif (command == 'SHOW'):
  39. client.send('SHOW')
  40.  
  41. else:
  42. sendText = typedInput
  43. client.send(sendText)
  44.  
  45. # *** process input from the user in a loop here ***
  46. # *** use client.send(someMessage) to send messages to the server
  47. except:
  48. client.stop();
  49. print 'You are exiting the chat. Goodbye!'
  50.  
  51. client.stop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement