smathot

Wait client

Mar 21st, 2013
126
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Generated by OpenSesame 0.27.2~pre3 (Frisky Freud)
  2. # Thu Mar 21 11:39:00 2013 (posix)
  3. # <http://www.cogsci.nl/opensesame>
  4.  
  5. set foreground "white"
  6. set subject_parity "even"
  7. set font_size "18"
  8. set description "Default description"
  9. set title "Wait client"
  10. set width "400"
  11. set font_bold "no"
  12. set coordinates "relative"
  13. set height "400"
  14. set mouse_backend "xpyriment"
  15. set start "experiment"
  16. set compensation "0"
  17. set sampler_backend "legacy"
  18. set keyboard_backend "legacy"
  19. set background "black"
  20. set subject_nr "0"
  21. set canvas_backend "xpyriment"
  22. set font_family "mono"
  23. set synth_backend "legacy"
  24. set font_italic "no"
  25.  
  26. define sketchpad wait_connect
  27. set duration "0"
  28. set description "Displays stimuli"
  29. draw textline 0.0 0.0 "Waiting for other PC" center=1 color=white font_family="mono" font_size=18 font_italic=no font_bold=no show_if="always"
  30.  
  31. define inline_script inline_script
  32. ___run__
  33. import socket
  34.  
  35. ip = '127.0.0.1' # The IP address of the other PC
  36. port = 40007 # An arbitrary port that matches the server
  37.  
  38. print 'Opening socket'
  39. socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  40. # Reducing the timeout will improve synchronization
  41. socket.settimeout(0.1)
  42. socket.bind((ip, port))
  43. print 'Listening'
  44. while True:
  45. try:
  46. s, addr = socket.recvfrom(1)
  47. print 'recv %s' % s
  48. except: # A timeout occurred
  49. s = None
  50. if s == '1':
  51. break
  52. print 'Server says hi!'
  53. print 'Saying hi back'
  54. socket.sendto('1', addr)
  55. print 'Done!'
  56. socket.close()
  57. __end__
  58. set _prepare ""
  59. set description "Executes Python code"
  60.  
  61. define sequence experiment
  62. run wait_keypress "always"
  63. run wait_connect "always"
  64. run inline_script "always"
  65. run done "always"
  66.  
  67. define sketchpad done
  68. set duration "keypress"
  69. set start_response_interval "no"
  70. set description "Displays stimuli"
  71. draw textline 0.0 0.0 "Done!" center=1 color=white font_family="mono" font_size=18 font_italic=no font_bold=no show_if="always"
  72.  
  73. define sketchpad wait_keypress
  74. set duration "keypress"
  75. set description "press"
  76. draw textline 0.0 0.0 "Press any key" center=1 color=white font_family="mono" font_size=18 font_italic=no font_bold=no show_if="always"
RAW Paste Data