Monday, 5 April 2021

How to send data to a Python SSL socket via Node.js

Context

I have a https server running on node.js that serves the requests of various client applications written in python and I want to enable peer to peer communication between the clients. To achieve this, I'm keeping track of the 'online' clients on the server that then sends the necessary data so that the peers can communicate between themselves.

My goal:

  1. The client applications opens three sockets (one for receiving messages from other clients, one for sending messages to other clients and one for receiving messages from the server - let's call this one notification socket)
host = '127.0.0.1'

listener_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ssl_listener_socket = ssl.wrap_socket(listener_socket, keyfile= pkey_path, 
    certfile= crt_path, cert_reqs= ssl.CERT_NONE, ssl_version=ssl.PROTOCOL_TLSv1_2)
ssl_listener_socket.bind((host, 0))
listener_name = ssl_listener_socket.getsockname()

sender_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ssl_sender_socket = ssl.wrap_socket(sender_socket, keyfile= pkey_path, 
    certfile= crt_path, cert_reqs= ssl.CERT_NONE, ssl_version=ssl.PROTOCOL_TLSv1_2)
ssl_sender_socket.bind((host, 0))
sender_name = ssl_sender_socket.getsockname()

notification_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ssl_notification_socket = ssl.wrap_socket(notification_socket, keyfile= pkey_path, 
    certfile= crt_path, cert_reqs= ssl.CERT_NONE, ssl_version=ssl.PROTOCOL_TLSv1_2)
ssl_notification_socket.bind((host, 0))
notification_name = ssl_notification_socket.getsockname()
  1. The client sends the various socket's ips and ports to the server
  2. When the server receives a connection request from a client that wants to talk to another client (clients are identified by usernames), if both of them are "online", the server opens two ssl sockets (one for each client), connects to each client's notification socket and sends it the information about the other client's sockets.

The issue

I'm not being capable of doing task #3. How can I create two ssl sockets in nodejs and send data to the python sockets?



from How to send data to a Python SSL socket via Node.js

No comments:

Post a Comment