TCP Direct Port Sample Program

Can anyone send me a sample Psychopy program where they use a TCP connection to send and receive data from another software program. The sample program I made for Visual Basic 6 just has a simple client server set up and passes messages between them. Something like this is easy to find for Python, but I’m not sure how to integrate that into Psychpy (can I just add the raw code?). I am new to Python. Any help is appreciated.

-Ken

TCP communication is available from the standard library in Python, so yes, you should be able to implement any standard examples you find within PsychoPy, e.g. such as the standard Python code here:

https://wiki.python.org/moin/TcpCommunication

i.e. simply import socket and go for it. I imagine that it will look very similar to what you have implemented in VB 6.

1 Like

You don’t mention whether you are using Builder or Coder. If you are unfamiliar with Python, the easiest approach would be to use Builder to create your experiment and then just insert a Code Component: this provides an interface to insert custom code components that get run at the right time. e.g. in the “begin experiment” tab, you would import socket and create the connection. Then at other relevant points (e.g. in the “begin routine” or “every frame” tabs), you would insert the code to actually send or receive messages.