Howdy, Stranger!

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

Supported by

Networked Chat experiment

Hey all,
I am trying to build an experiment for simple chat between 2 participants.
One can be the server and other can be the client. I found some samples for OpenSesame 2 but couldn`t find enough data for version 3.2.

Are there any other person who made a similar experiment?
Regards

Comments

  • edited September 7
    Hi,

    Creating an experiment like that is possible, but how easy it is depends on the details. What *exactly* do you want to do? How should participants interact? And does the experiment consist only of chatting, or is this embedded in other tasks?

    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

  • Hi Sebastiaan,
    Thanks for the reply, actually it will be part of a larger experiment and connecting two users from separate computers will be part of the task.
    Two users, will try to complete tasks by cooperating with each other. They will be shown different inputs (images, videos or texts).
    They will communicate with each other by sending messages and try to find the answer.

    Is it a bit more clear? I can give more details.
    Regards,
    NB

  • Hi Newbee,

    This sounds like a fairly complicated experiment. Doable, but not trivial at all. Given that you don't seem very experienced in coding, I doubt that you'll be able to implement this, not without a large amount of help (more than you'll likely get on the forum). I may be wrong, but that's the feeling I'm getting.

    So how experienced are you, and do you think you'll be able to manage an experiment that will require a considerable amount of Python coding?

    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

  • Hello Sebastiaan,
    I am not very experienced on coding, but I found some walkaround and simplified the experiment.
    A separate application will be used for chat and Opensesame will get input from only one user, which makes things a lot easier. I will work on it and ask for support for any obstacles I met.
    Regards,
    NB

  • Hello again Sebastiaan,
    For last couple of days, I tried again to make this experiment work with client and server.
    Now, server and client can make a connection, but they continuously send messages.
    What I want is, when server sends a specific message, client to show screen1 and if server sends another value show screen2.
    This way I try to change screens on client side with feedbacks from the server.
    Attached you can find the simplified experiment, I can not go further than the inline script, because it crashes when I started it.
    Do you have any idea to make it as simple as possible?
    I think establishing the connection and following the steps in the experiment and sending messages when user submit response to the questions which will trigger actions in client side will be what I need. But I couldn`t do it.

  • edited October 10

    Hello again,
    I made some more changes and now both instances can make the connection but I want the message to be sent to change based on an internal variable (a form input). If this value (var1_1) equals to 33, it should send 30 and if it is some other value it should send 20. But when I run the application I get an error, which is shown below.
    And also, even the input is correct, client always receives 20.

    **Server Script:**
    HOST = ''
    PORT = 8000
    
    
    def task5():
        print ('task 5')
    
    s = socket(AF_INET, SOCK_STREAM)
    s.bind((HOST, PORT))
    s.listen(1)
    conn, addr = s.accept()
    print 'Connected by', addr
    
    var1_1 = "" 
    result = str(var1_1)
    if result == '33':
        var = '30'
    else:
        var = '20'
    
    
    while True:
        data = conn.recv(1024)
        print "Received ", repr(data)
        reply = var
        # print (str(data))
        if str(data) == '50':
            task5()
            conn.sendall(reply)
        elif data == '100':
            conn.close()
            conn.sendall('quit')
            break
        else:
            break
            try:
                conn.sendall('quit')
            except:
                print ('client exited')
    
    conn.close()
    
    **Client Script:**
    from socket import *
    
    HOST = 'localhost'
    PORT = 8000
    s = socket(AF_INET, SOCK_STREAM)
    s.connect((HOST, PORT))
    
    
    def task1():
        print("task one")
        return 'server did task 1'
    
    
    def task2():
        print("task two")
        return 'server did task 2'
    
    var3 =''
    def task3():
        print("task three")
        var3 = '880'
        print(var3)
        return 'server did task 3'
    
    var = '50'
    while True:
        message = var
        s.send(message)
        print "Awaiting reply"
        reply = s.recv(1024)
        print "Received ", repr(reply)
        # print(repr(reply))
        if reply == '10':
            task1()
            break
        elif reply == '20':
            task2()
            break
        elif reply == '30':
            task3()
            break
        elif reply == 'quit':
            break
    s.close()
    
    
    **Error message:**
    Unexpected error
    
    item-stack: experiment[run].Experiment_1[run].Task_Sequence[run]
    exception type: AttributeError
    exception message: 'str' object has no attribute 'var1_1'
    time: Wed Oct 10 09:01:05 2018
    
    Traceback:
      File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libqtopensesame\misc\process.py", line 157, in run
        exp.run()
      File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\experiment.py", line 456, in run
        self.items.execute(self.var.start)
      File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\item_store.py", line 103, in execute
        self.run(name)
      File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\item_store.py", line 122, in run
        self[name].run()
      File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\sequence.py", line 51, in run
        self.experiment.items.run(_item)
      File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\item_store.py", line 122, in run
        self[name].run()
      File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\sequence.py", line 51, in run
        self.experiment.items.run(_item)
      File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\item_store.py", line 122, in run
        self[name].run()
      File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\sequence.py", line 50, in run
        if self.python_workspace._eval(cond):
      File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\base_python_workspace.py", line 141, in _eval
        return eval(bytecode, self._globals)
      File "<conditional statement>", line 1, in <module>
    AttributeError: 'str' object has no attribute 'var1_1'
    
  • Hi,

    I haven't look at your experiment, so I can't tell you whether you are on the right track, but the specific problem here is that you are overwriting opensesame's builtin var object. It is needed for the experiment to run properly, so it is really a bad idea to do stuff like that; var = '30'. So, simply use different variable names and you should be fine.

    Good luck,

    Eduard

  • Thanks Eduard,
    Seems like it was one of the main problems, now I changed the name to var_sent instead of var.
    and now it can correctly send the message and close the connection.

Sign In or Register to comment.