Competitive tasks in PsychoPy

Hi,

I am currently involved in the development of several studies in which participants compete/cooperate with each other in different yet simple “games”, including simple stimulus cued button presses and a custom “Pong” game.

As I am looking for an alternative to NeuroBS’ Presentation and MATLAB, my question here is how realistic these levels of interaction between different PCs are within PsychoPy. The only information I have been able to find is a post from 2016 (Support for interactive studies). The solutions offered here do not sound very feasible for a paradigm in which reaction time is of importance.

Any reference to a tutorial for generating such setup in PsychoPy or short examples would be greatly appreciated.

Anything is possible, because you have access to the complete Python language under the hood, but this would definitely require custom code to be written.

If real-time interaction is important, I’d suggest that you set up a messaging protocol where each PC sends UDP messages over the local network to the other one. If the computers are on the same ethernet switch (and ideally isolated from the internet and other local networks), these messages are extremely fast and reliable, and easy to send and receive in Python. Within the duration of each screen refresh, you would have more than enough time to check for a message and update the stimuli on screen accordingly.

Sending strings formatted as XML or JSON can provide a flexible way to send the data required, which you can easily parse to take the actions you want in response. e.g.

<message>
    <mouse>  
        <x>101</x>
        <y>202</y>
        <left_button>True</left_button>
        <right_button>False</right_button>
    </mouse>
    <keypress>'space'</keypress>
</message>  

or even send string representations of Python dictionaries and then eval() them to actual dictionary objects.

Dear Michael,

Thank you for the suggestions. After some further googling I came across some interesting guides on using sockets in python (https://www.youtube.com/watch?v=Lbfe3-v7yE0).

Though I’m familiar with programming in a few other environments I’m quite new to networks and communication. Most feedback which I get seem to highly recommend TCP/IP over UDP, citing that UDP can be irreliable. Is there a particular reason why you do suggest UDP?

UDP is fast and highly reliable on a closed network, and slightly easier to work with than TCP messages.

In the real-world (i.e. on the wilds of the internet), UDP is used for things like streaming video and audio, where if there is a blip in communications, you don’t care about going back and reconstructing all the data - that moment has passed. There is accordingly no mechanism for noticing that a message has been missed. TCP meanwhile, would be used for things like sending a datafile, where you don’t want a single byte to go astray. So messages can be received out-of-order and reconstructed to produce the sent data perfectly, because that is more important than the actual speed of transmission.

But in a lab, ideally with the computers disconnected from other competing network traffic, UDP is rock-solid and easy to use. All you need to know is the IP address of the recipient and the port that it is listening on. There is no other back-and-forth communication protocol required.