Socket communication from processing to Python

Asked 2 years ago, Updated 2 years ago, 71 views

Looking for a way to communicate string-only socket from processing to Python.

Send data from Python to Processing via socket communication|Qiita

I would like to reverse the above site.
I looked it up, but I couldn't find it on my own.

Thank you for your cooperation.

python python3 processing

2022-09-30 21:34

1 Answers

Just like the site code in the question, it is a sample code that sends text messages unilaterally from Processing to Python in the same machine.

Processing side (http://www2.kobe-u.ac.jp/~tnishida/course/2012/programming/ServerClient.pdf)
Start the server side first and match the port number to the server.

import processing.net.*; 
Client client;

void setup() { 
  client=new Client(this, "127.0.0.1", 50007); 
} 

void draw() { 
  client.write("hello");  
} 

Python side (Python document)

#Echo server program
import socket

HOST='#Symbolic name meeting all available interfaces
PORT=50007#Arbitrary non-privileged port
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as:
    s.bind((HOST, PORT))
    s.listen(1)
    conn,addr=s.accept()
    with conn:
        print('Connected by',addr)
        while True:
            data=conn.recv (1024)
            if not data —break
            print(data)


2022-09-30 21:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.