Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[solved] Simultaneous display of videos on two laptops

edited March 2013 in OpenSesame

Hi,

I'm designing an experiment for my master thesis, in which I would like to show 2 participants emotion-eliciting film clips. Is it possible to show the videos simultaneously on two laptops? They will be watching the same film clip in the same room but on different laptops. Is it achievable that the film clips start at the same time after both participants confirm ready? After viewing they will finish a questionnaire regarding their emotional experience separately on each laptop.

I'm a beginner of OpenSesame and have little experience in coding. I would be very appreciated if some experienced users would give me some suggestions. :) Thank you in advance!

Ying

Comments

  • edited 3:43AM

    Hi Ying,

    Welcome to the forum!

    It's possible, but will require some inline scripting. Basically, what you would need to do is set up a connection between the two computers, where one is the server and the other is the client. Then they communicate their 'ready' status until both computers are ready. You would do this with the Python socket module, as described here:

    This is not as difficult as it sounds, but not trivial either. If you describe in sufficient detail what you want to do, we could help you get started with a short example script.

    Cheers!
    Sebastiaan

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • edited 3:43AM

    Hi Sebastiaan,

    Thank you for your reply!

    Here is the thing,

    image

    Basically, two laptops would be running the same experiment, presenting the same video stimulus and collect responses to the questionnaires. Before presenting the stimulus, the laptops should communicate with each other that they are ready (as the red arrows show), and start the video together (in the practice session or later in the main session).

    Like you said, the server should send signal to the client to confirm the status. If the client is slower than the server, the server would be waiting until the client finish their tasks and get ready to video-session. If the client goes faster than the server, then reversely it should wait for the signal from the server before every start of videos.

    Hopefully my description is detailed enough. :) Thank you again for your help!

    Best regards,

    Ying

  • edited 3:43AM

    Hi Ying,

    As I said, you will need two inline_script items. These will pause the experiment until on both computers the inline_script item is reached, and then the experiment will continue on both computers. This will allow you to sync the systems.

    The two scripts are similar, but slightly different. The server script:

    import socket
    
    ip = '127.0.0.1' # The IP address of the other PC
    port = 40007 # An arbitrary port that matches the client
    
    print 'Opening socket'
    socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    # Reducing the timeout will improve synchronization
    socket.settimeout(0.1)
    print 'Listening'
    while True:
        socket.sendto('1', (ip, port))
        print 'send 1'
        try:
            s, ip = socket.recvfrom(1)
            print 'recv %s' % s
        except: # A timeout occurred
            s = None
        if s == '1':
            break
    print 'Client says hi!'
    socket.close()
    

    The client script:

    import socket
    
    ip = '127.0.0.1' # The IP address of the other PC
    port = 40007 # An arbitrary port that matches the server
    
    print 'Opening socket'
    socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    # Reducing the timeout will improve synchronization
    socket.settimeout(0.1)
    socket.bind((ip, port))
    print 'Listening'
    while True:
        try:
            s, addr = socket.recvfrom(1)
            print 'recv %s' % s
        except: # A timeout occurred
            s = None
        if s == '1':
            break
    print 'Server says hi!'
    print 'Saying hi back'
    socket.sendto('1', addr)
    print 'Done!'
    socket.close()
    

    Of course you will need to change the IP address to match those on your network.

    To see these script in action, see these dummy experiments:

    Cheers!
    Sebastiaan

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • edited 3:43AM

    Hi Sebastiaan,

    I've tried to run the dummy experiments you gave me through the links. There is a error on the client computer, the message is:
    'ascii' codec can't decode byte 0xfc in position 77: ordinal not in range(128).

    The same error message appeared, when I only add the client script into the inline_script of my experiment on the client computer. And the server computer stands still while it has no feedback from the client.

    I've changed the IP addresses. I didn't change the ports because I don't know where I can get the numbers. I suppose every computer should be the same with ports. Except these, I've changed nothing. Would you please tell me what this error message means and what I should correct? Thanks a lot!

    Best regards,
    Ying

  • edited 3:43AM

    I've tried to run the dummy experiments you gave me through the links. There is a error on the client computer, the message is: 'ascii' codec can't decode byte 0xfc in position 77: ordinal not in range(128).

    What operating system and version of OpenSesame are you running? Also, there should be a full error message in the debug window, could you please post this?

    I didn't change the ports because I don't know where I can get the numbers. I suppose every computer should be the same with ports.

    Indeed: The ports are arbitrary, as long as they match between server and client, and are not used by any other software. 40007 should be fine, and if not you will get an informative error message about this.

    Cheers!

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • edited March 2013

    Hello,

    I'm runnig Window 7 and OpenSesame 0.27.1.

    The full error message in the debug window:

    image

    Thanks!

    Ying

  • edited 3:43AM

    Hi Ying,

    The error indicates that the address is invalid. (Actually there is also an error due to the special characters in the real error message.). This is presumably related to your network configuration, so I cannot really say much more about it. Perhaps you can try first if you can get it to work by running both the client and the server on the same computer (in which case the IP is 127.0.0.1). This should work, and then you can go from there?

    Cheers,
    Sebastiaan

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • edited 3:43AM

    Hello Sebastiann,

    I've tried to run on the same computer. It works very well. So it must be the invalid IP-address. Maybe the two PC are behind routers, so there is problem with the client IP.

    I've change the client IP address into '0.0.0.0', which will llisten for all incoming hosts. And it worked quite well on 2 PCs! Huray, Huray, Huray!!!!! Finally!

    Thank you very very much for helping me solve the problem. Wish you a happy Easter!

    Ying %%-

  • edited 3:43AM

    Great! Good luck with your experiment.

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • edited 3:43AM

    Hello Sebastiaan,

    I have a problem again with the server/client synchronisation. I've successfully run the scripts on two PCs, but it seems that the server should always go ahead of the client. When the client is far away ahead of the server, which means that I press the key on the client PC, let's say 15 seconds earlier, before I press it on the server. What happens is, that the server remains on "waiting for other PC" and keep sending 1 to the client, whereas the client moves on the status "done!". Why is it happening?? Is there a pre-condition in the codes that the server should always be the one that initials the connection?

    This is important for me because the participants would be filling out questionnaires before they start the film clip. And the time is not controllable. So it might be very possible that the participant on the client-PC goes faster than the server-PC. And the interval could be larger than few seconds.

    Do you have any suggestions to fix it? Thanks a lot!

    Ying

  • edited 3:43AM

    The scripts should be symmetrical. Once they both reach the 'wait' script, they both advance. In other words, when the client script prints Done!, the server script should print Client says hi! at the same time.

    Based your post I can't really tell what the problem is. First, are you sure that the problem is with the script, not a hang-up somewhere else in your experiment(s)? Second, does it work as expected when you run both scripts on the same computer?

    Cheers!

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • edited 3:43AM

    Could this be a problem with the IP? Because the two computers are behind the same router, they do not have a true valid IP. So I changed the client script by writing the IP of the other Computer with 0.0.0.0., so that it receives any signal from outside. In this case the scripts may not be symmetrical because the client listen to the outside and wait for signals coming but do not send signals aiming at any IP.

    Running on the same computer has always no problem, although I also changed one IP into 0.0.0.0, the other 127.0.0.1. I don't know why.

    I don't know how to solve the "INVALID-IP Adress" problem. Is there maybe a way solving the problem with the script?

    Thanks!!!

  • edited 3:43AM

    Could this be a problem with the IP? Because the two computers are behind the same router, they do not have a true valid IP.

    The fact that you're behind a router is not a problem. When a computer is on a network, it always has a regular IP address that you can find in the network settings of your operating system. A router may translate that IP address into another address for communication with the outside world (i.e. the internet). That's why you may see different IP addresses when you compare a site like http://www.whatismyip.com/ and your local IP address. In your case, you need the local IP address as reported by your operating system.

    I don't know how to solve the "INVALID-IP Adress" problem. Is there maybe a way solving the problem with the script?

    I don't really understand this question. Do you receive an error message that says 'INVALID-IP Address'?

    The best thing is probably to consult someone who knows how your network is configured, and who can help you to make the scripts work on your particular system. In general, the scripts should work, I believe, as you can tell from the fact that they work on the same PC.

    Cheers!

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

Sign In or Register to comment.