This class will open a port in Houdini an emulate a terminal with the ability to send and receive commands.
Using ports to control the Houdini app.
Date Created:Friday December 29th, 2006 03:41 AM
Date Modified:Sunday October 03rd, 2010 05:53 PM
#!/usr/bin/python class hou: import socket hou = socket.socket(socket.AF_INET, socket.SOCK_STREAM) def __init__(self): self.hou_conn() print 'Connected to Houdini...' def hou_conn(self): self.hou.connect(('localhost',12000)) return() def send_data(self,command): self.hou.send(command + '\n') return() def get_data(self): delimiter = '\x00' buffer = "" while delimiter not in buffer: buffer = buffer + self.hou.recv(8192) return(buffer[:-2]) def hou_close(self): self.hou.close() return() def command(self,command): self.send_data(command) buffer = self.get_data() print buffer class term(hou): def __init__(self): hou.__init__(self) print 'type "exit" to close connection...' while 1: self.pwd() self.hpwd = "%s%s" % (self.hpwd, '/->') line = raw_input(self.hpwd) if line == 'exit': self.hou.close() print 'Connection closed...' break self.command(line) def pwd(self): self.send_data('pwd') buffer = self.get_data() self.hpwd = buffer
Downloads:
Download: socket.py 2 KB
Please login or Click Here to register for downloads
Python to Houdini by Dan Lynch
is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
Based on a work at www.3daet.com
Permissions beyond the scope of this license may be available at http://www.3daet.com
