Search code examples
python-2.7socketsmaya

Python Socket to Maya Receive data is none


Similar to this question here, I'm trying to connect Python to Maya via socket and commandPort. Currently, it works. I can send information to Maya but I cannot receive it.

In my code, on the Python side, I have:

clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
clientsocket.connect(("127.0.0.1", 1234))
clientsocket.send("import maya.cmds as cmds\ncmds.ls(selection=1)")
data = clientsocket.recv(4096)
print(data)

This returns None. I need the selection listed and sent back to Python. Because of how the string is set up, I cannot create a viable return string. So how do I get a return?

On the Maya side, my port is set as such:

import maya.cmds as cmds
cmds.commandPort(n=":1234", sourceType="python", echoOutput=True, bufferSize=4096)

What am I doing wrong?

I'm utilizing Maya 2016.5 and Python 2.7.3, if that helps.


Solution

  • I solved my own problem.

    In Python, I created a listening server. In Maya, I opened a commandPort. I sent commands to Maya with a return to the listening server.

    This way, I can effectively send and retrieve data from Maya to Python, from Python to Maya.