makehumancommunity / makehuman

This is the main repository for the MakeHuman application as such.
http://www.makehumancommunity.org
Other
1.18k stars 244 forks source link

Cannot connect to makehuman socket -Socket error: [WinError 10054] An existing connection was forcibly closed by the remote host #246

Open andytriboletti opened 5 days ago

andytriboletti commented 5 days ago

I downloaded the windows app and synchronized the database. Then I ran a python script to connect to the server.

C:\Users\Andy\blender>python makehumansocket2.py
Connected to MakeHuman socket server.
Socket error: [WinError 10054] An existing connection was forcibly closed by the remote host
Failed to generate random model.
Socket connection closed.
import socket
import json
import time

def send_command(command):
    try:
        s.sendall((command + '\n').encode('utf-8'))
        response = s.recv(1024)
        return response.decode('utf-8')
    except socket.error as e:
        print(f"Socket error: {e}")
        return None

def main():
    # Connect to MakeHuman socket
    host = 'localhost'
    port = 12345

    global s
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    try:
        s.connect((host, port))
        print("Connected to MakeHuman socket server.")

        # Generate a random model
        random_model_command = json.dumps({
            "command": "randomize",
            "arguments": {}
        })
        response = send_command(random_model_command)
        if response:
            print("Random model generated:", response)
        else:
            print("Failed to generate random model.")
            return

        # Allow some time for the model to generate
        time.sleep(2)

        # Export the model
        export_command = json.dumps({
            "command": "export",
            "arguments": {
                "exporter": "mhx2",  # Change to your desired format, e.g., 'obj', 'fbx'
                "path": "C:/path/to/save/exported_model.mhx2"  # Update the path as needed
            }
        })
        response = send_command(export_command)
        if response:
            print("Model exported:", response)
        else:
            print("Failed to export model.")
    except socket.error as e:
        print(f"Unable to connect to MakeHuman socket server: {e}")
    finally:
        s.close()
        print("Socket connection closed.")

if __name__ == "__main__":
    main()
Aranuvir commented 4 days ago

Well I have two things to say here.

1- Where does this script originate from? AFAIK that's not how things work, or I have missed some greater code changes, since I haven't been active for a while.

You cannot simply throw random data against the server and then hope for the best. If you want to know what should be in the JSON data, take a look at plugins/1_mhapi/JsonCall.py and plugins/8_server_socket. The xxxops.py files show the available functions (aka commands in your code).

2- The issue in the application is that arbitrary JSON data leads to a KeyError and a consecutive SIGABRT (on my system), shutting down the application, probably because the code is running async. This absolutely should not happen and is a serious bug. On the other hand the intention of the code is mainly to communicate with Blender over localhost by our plugins. Chances a rare it will ever see unexpected JSON data, except it is used outside its intended specifications. Therefore the issue has low priority.

andytriboletti commented 4 days ago

The script is from a combination of claude, chatgpt, gemini. I want to use makehuman from a game so I am using socket. Could you provide sample code documenting makehuman socket code in the readme?

On Sat, Jun 29, 2024, 12:23 PM Aranuvir @.***> wrote:

Well I have two things to say here.

1- Where does this script originate from? AFAIK that's not how things work, or I have missed some greater code changes, since I haven't been active for a while.

You cannot simply throw random data against the server and then hope for the best. If you want to know what should be in the JSON data, take a look at plugins/1_mhapi/JsonCall.py and plugins/8_server_socket. The xxxops.py files show the available functions (aka commands in your code).

2- The issue in the application is that arbitrary JSON data leads to a KeyError and a consecutive SIGABRT (on my system), shutting down the application, probably because the code is running async. This absolutely should not happen and is a serious bug. On the other hand the intention of the code is mainly to communicate with Blender over localhost by our plugins. Chances a rare it will ever see unexpected JSON data, except it is used outside its intended specifications. Therefore the issue has low priority.

— Reply to this email directly, view it on GitHub https://github.com/makehumancommunity/makehuman/issues/246#issuecomment-2198251528, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAATIBBVDVLIPFBZL6FDD4TZJ3NO3AVCNFSM6AAAAABKCKJSCGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOJYGI2TCNJSHA . You are receiving this because you authored the thread.Message ID: @.***>

black-punkduck commented 4 days ago

afaik it is not a documented open API. Why did neither chatgpt, nor claude, nor gemini mention it?

And yes, each socket works like this. The secret is in export_command which might be 3 lines or 3000 lines. When it becomes interesting, AI usually starts to create a lot of fantasy XD

To use the API:

check the commands in 8_server_socket ... it will be like 3000 lines ... meshops.py will get meshes, or proxies, skeleton etc. Furthermore you need to understand the meaning of positions, UV coordinates, proxies ... and when all that will work, we might change the socket because WE need a different functionality.

A non-documented API for internal purposes is not really meant for this.

An open API or one just calling the file-exporter we don't have. Btw.: mhx2 is also an internal format which is only known to blender + makehuman.

And it will not be implemented in the old version.

At least it could be an idea for the new one, which unfortunately needs some time to be usable ;)

In that case, I guess I should add both, a remote trigger to export a file via e.g. gltf + a classical open API, where people need to understand the complete logic.

andytriboletti commented 4 days ago

Thank you for answering, I appreciate it.