Jump to content

Q: Closeport Via Python Socket


TheUsualAlex

Recommended Posts

Hello,

I was just wondering about this one: So after I established a connection with Houdini via python (or perl) socket, is it possible to send a closeport command to Houdini via socket in order to tell Houdini to close the port your python script is connecting (assuming that you're done with the session)?

Thus far, I am able to send any other commands into Houdini from Python/Perl, however, I haven't been able close the port from there. My current work around is via a system call to hcommand which worked.

Much thanks!

-A

Link to comment
Share on other sites

If you are indeed done with the session, then you can issue "closeport", disconnect (from the Python side), and the port will close on the Houdini side. If you need the Houdini side to shut down while the Python side is still connected ... then I'm also at a loss (fortunately I've never needed to do this). The "closeport" command seems to get queued and executed as soon as there are no connections.

I don't know if this helps or not :)

Cheers!

Link to comment
Share on other sites

Hello there,

The "closeport" command seems to get queued and executed as soon as there are no connections.

That made sense! :)

Oddly enough, it seems that a very simple 3 liner python, I can send "closeport" command to have Houdini close the port successfully. But in the OO format, I couldn't get it to close even if I place this in the destructor... I am at a lost... :cry2:

so I have something like:

# Assuming self.sock is connected successfully through socket module
def __del__(self):
     print "calling destructor. port", self.port
     self.sock.send("closeport "+str(self.port)+"\n")
     self.sock.close()

No workie thus far... :(

Anyhow, I'll study into this further. I am still a freshmeat with python.

Much thanks!

Alex

Link to comment
Share on other sites

Well, thanks to George, we finally figured out what's happening here. Let's see if I can explain it as well as George explained it to me...

What's happening in the line:

self.sock.send("closeport "+str(self.port)+"\n")

is that when python is sending the closeport command through the socket.send method, it immediately closes the gate before Houdini has a chance to read that command in due to timing issues. Thus by the time Houdini actually get to reading that data, nothing is coming in even though Python reported that it has successfully sent X amount of bytes and be done. It's not Houdini's or Python's fault as far as I understand it. So what I have to make sure now is that after the send method is called, python is also waiting to hear back from Houdini before doing anything else, which of course, brought on another issue (I think): what happen if Houdini is doing something else and takes a while to respond.

Hence:

...snip...

def __del__(self):
    print "calling destructor. port", self.port
    self.send("closeport "+str(self.port))
    self.sock.close()

def send(self, hcmd):
     self.sock.send(hcmd + "\n")
     buffer = ""
     while '\x00' not in buffer:
          buffer += self.sock.recv(self.bufferSize)
     return buffer.strip('\n|\x00')

...snip...

Anyhow, George probably wants to correct me on some info above. Sorry, John Coldrick, for redoing the same wheel. :D I am just tacking on some extra features that I thought was convinient. :)

Much thanks!

Alex

Link to comment
Share on other sites

Anyhow, George probably wants to correct me on some info above.

No Alex, you did a good job. It's really just Houdini refusing to perform any action if the sender has closed the socket. And by the time Python sends out the "closeport" command, it's closed its end of the socket, and so Houdini detects that and decides not to run any more commands.

George.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...