McpStatus - what port is listening?

As I work with multiple rhino files/instances throughout the day, I would like a way to check what port rhino is currently listening to. If that is not possible now then I suggest a new command to show me the port. McpStatus

Good idea, logged.. RH-98047

If I understand correctly, the 2nd instance of rhino takes over the port 10500? Maybe the next instances could go to the next available port 105001 and so on.

Here is a snippet your can run that gives you the port in the Rhino command line.

import System, Rhino

pid = System.Diagnostics.Process.GetCurrentProcess().Id
asm = [a for a in System.AppDomain.CurrentDomain.GetAssemblies()
       if a.GetName().Name == "RhinoMcpPlatform"]
if not asm:
    msg = "MCP plugin not loaded"
else:
    t = asm[0].GetType("RhMcp.RhinoMcpHost")
    BF = System.Reflection.BindingFlags
    a = System.Array[System.Object]([Rhino.RhinoDoc.ActiveDoc, 0])
    ok = t.GetMethod("TryGetPortFor", BF.Public | BF.NonPublic | BF.Static).Invoke(None, a)
    msg = ("listening on port " + str(a[1])) if ok else "no MCP listener"
Rhino.RhinoApp.WriteLine("Rhino PID {0}: {1}".format(pid, msg))