Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
andytriboletti opened this issue Jun 28, 2024 · 4 comments
Assignees

Comments

@andytriboletti
Copy link

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
Copy link
Collaborator

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
Copy link
Author

andytriboletti commented Jun 29, 2024 via email

@black-punkduck
Copy link
Contributor

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
Copy link
Author

Thank you for answering, I appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants