bl_info = { "name": "XMLRPC Server", "author": "KristenH", "version": (0, 5, 0, 1), "blender": (2, 79, 0), "category": "System" }
from xmlrpc.server import SimpleXMLRPCServer import threading, time from socketserver import ThreadingMixIn import bpy import sys import socket print() from queue import Queue
Simple server class
class SimpleServer(ThreadingMixIn, SimpleXMLRPCServer): pass # The same statement as Null in C++, Java, C# etc.
The command function
def command(com): com='import bpy\n'+com exec(com) # Trigger command to server return com
The server data
def server_data(): return bpy.app.version_string, bpy.context.blend_data.filepath, socket.gethostname()
def pscan(host='localhost', port=8000): # Setting up a socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) proxy = (host, port) try: con = sock.connect(proxy) return True except: pass
class ServerThread(threading.Thread):
def init(self, host='localhost', port=8000):
self.proxy = (host, port)
self.server = SimpleServer(self.proxy)
self.port = port
self.host = host
threading.Thread.init(self)
# self.server_thread.setDaemon(True)
self.server.register_introspection_functions()
self.server.register_function(command, "command")
self.server.register_function(server_data, "server_data")
self.version_string = bpy.app.version_string
self., bpy.context.blend_data.filepath, socket.gethostname()
A class shows a server panel in Blender
class ServerPanel(bpy.types.Panel): bl_label = "Server Panel" bl_idname = "Object_PT_server" bl_space_type = 'PROPERTIES' bl_region_type = 'WINDOW' bl_category = "Shortcuts"
bl_info = {
"name": "XMLRPC Server",
"author": "KristenH",
"version": (0, 5, 0, 1),
"blender": (2, 79, 0),
"category": "System"
}
from xmlrpc.server import SimpleXMLRPCServer
import threading, time
from socketserver import ThreadingMixIn
import bpy
import sys
import socket
print()
from queue import Queue
# Simple server class
class SimpleServer(ThreadingMixIn, SimpleXMLRPCServer):
pass # The same statement as Null in C++, Java, C# etc.
# The command function
def command(com):
com='import bpy\n'+com
exec(com) # Trigger command to server
return com
# The server data
def server_data():
return bpy.app.version_string, bpy.context.blend_data.filepath, socket.gethostname()
def pscan(host='localhost', port=8000):
# Setting up a socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
proxy = (host, port)
try:
con = sock.connect(proxy)
return True
except:
pass
class ServerThread(threading.Thread):
def __init__(self, host='localhost', port=8000):
self.proxy = (host, port)
self.server = SimpleServer(self.proxy)
self.port = port
self.host = host
threading.Thread.__init__(self)
# self.server_thread.setDaemon(True)
self.server.register_introspection_functions()
self.server.register_function(command, "command")
self.server.register_function(server_data, "server_data")
self.version_string = bpy.app.version_string
self., bpy.context.blend_data.filepath, socket.gethostname()
# A class shows a server panel in Blender
class ServerPanel(bpy.types.Panel):
bl_label = "Server Panel"
bl_idname = "Object_PT_server"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_category = "Shortcuts"
def draw(self, context):
layout = self.layout
row = layout.row()
server = None
x = 8000
attempts = 0
while(server is None):
con = pscan(port=x)
if con is not None:
print(con, 'found server on', 'localhost:',x)
row.label(text="Server found on: localhost:" + str(x) + "\n")
x+=1
else:
# time.sleep(5.0)
server = ServerThread(port=x)
# Make sure the first port is the start up port.
# row.label(text="Started the server with:" + str(server.host) + ":" + str(server.port) + "\n")
print(attempts, "Started the server with:", server.host, ":", server.port)
server.start()
# row.label(text="... Press Ctrl+C to exit\n")
#print("... Press Ctrl+C to exit")
attempts+=1
break
# Blender code below
def register():
bpy.utils.register_class(ServerPanel)
#bpy.utils.register_class(SimpleServer)
#bpy.utils.register_class(ServerThread)
def unregister():
bpy.utils.unregister_class(ServerPanel)
#bpy.utils.unregister_class(SimpleServer)
#bpy.utils.unregister_class(ServerThread)
if __name__ == "__main__":
register()
Blender code below
def register(): bpy.utils.register_class(ServerPanel) #bpy.utils.register_class(SimpleServer) #bpy.utils.register_class(ServerThread)
def unregister(): bpy.utils.unregister_class(ServerPanel) #bpy.utils.unregister_class(SimpleServer) #bpy.utils.unregister_class(ServerThread)
if name == "main": register()