How to connect client side Python socket to Node.js / socket.io?

I want to connect Blender (v2.55) to a web page via sockets.

For the web part, I can use Node.js and socket.io. I already used a little Node.js / socket.io, this is not a problem, I think.

Now for Blender, it runs on Python 3.1, so I already have sockets, and I can add libraries if necessary. I'm new to Python sockets, can I directly connect the client to Node.js / socket.io?

I tried using the base code from a Python document:


import socket
import sys

HOST, PORT = "127.0.0.1", 8080
data = "Hello from Blender"

# Create a socket (SOCK_STREAM means a TCP socket)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Connect to server and send data
sock.connect((HOST, PORT))
sock.send(bytes(data + "\n","utf8"))

# Receive data from the server and shut down
received = sock.recv(1024)
sock.close()

print("Sent:     %s" % data)
print("Received: %s" % received)

This is the result:

Sent: Hello from Blender
Received: b ''

Blender seems to be connected but not receiving data. In addition, Node shows that the new client is not connected ...

Do I need anything else? If someone can help me ...

+3
1

/. , , - TCP-. node.js/socket.io TCP. , socket.io, , - (websockets, longpolling, htmlfile, ). , . Websockets - . . , websockets.

0

Source: https://habr.com/ru/post/1772826/


All Articles