psychopy 定作实验程序 https://item.taobao.com/item.htm?spm=a230r.1.14.6.Q6E2OW&id=530690095131&ns=1&abbucket=15#detailpython
有的实验会用到两台电脑联机,要求被试互相为对方分配赏金或者得分,要求被试之间合做或者竞争。有时咱们会用假被试,即让被试玩单机的,但却告诉他是联机的。这个方式虽然很机智,但有时也充满了遗憾——若是真的能够让被试作真正的联机任务该多好!网络
在这里,分享一个联机通信脚本,如下是脚本运行过程和脚本文件。具体的思路请自行参悟,或者app
from pydoc import help import socket help(socket.socket)
秒拍视频 http://www.yixia.com/u/paike_r2r9ujpkf9socket
# -*- coding: utf-8 -*- """ Created on Sun Sep 04 22:53:45 2016 @author: zbg """ import socket import sys import threading def WaitFor(connect, s): while connect.recv(1024) != s: pass HOST = '192.168.1.102' PORT = 8888 data = '' s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((HOST, PORT)) s.listen(10) con, addr = s.accept() WaitFor(con, 'start') from psychopy.visual import Window, ImageStim, TextStim from psychopy import core, event, gui, clock done = False win = Window(fullscr = True) while not done: key = con.recv(1024) if key =='q': done = True t =TextStim(win, key ,pos=(0,-0.0), height = 1.5) t.draw() win.flip() win.close() s.close()
# -*- coding: utf-8 -*- """ Created on Mon Sep 05 16:33:06 2016 @author: zbg """ import socket import threading ip = '192.168.1.102' sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((ip, 8888)) sock.send('start') from psychopy.visual import Window, ImageStim, TextStim from psychopy import core, event, gui, clock win = Window(fullscr = True) t =TextStim(win, u"我是键盘,按q退出" ,pos=(0,-0.0)) t.draw() win.flip() keys = event.getKeys() while 'q' not in keys: if len(keys) > 0: print keys[0] sock.send(keys[0]) keys = event.getKeys() sock.send('q') sock.close() win.close()