Help with processing.net.Client
in
Core Library Questions
•
2 years ago
Hey everyone, I'm working on a Processing client for my pet project a multiplayer game: the server of which is written in Python. The server connection works fine from Python, and great from Processing unless I want the Processing to read the response from the server. I need a method to read the response from the custom non-HTTP server after making a request. Thanks in advance.
I've included some code snippets, though the indenting got a little messed up on the Python server part.
The working function that makes a request to the server but doesn't return response:
- void sendCommand(String cmd) {
- client = new Client(this,ip,port);
- client.write(cmd);
- }
(client is an instance of Client, ip is a string, and port is an integer)
The function that is supposed to get the response from the server after making a request, but doesnt:
- String getResponse(String cmd) {
- client = new Client(this,ip,port);
- client.write(cmd);
- while (client.active()) {
- if (client.readString() != null) {
- return client.readString();
- }
- }
- return null;
- }
The important part of the Python server:
- while True:
- s.listen(1)
- conn, info = s.accept()
- data = conn.recv(1024) #a request
- console("Request from client: " + repr(data))
- #...
-
conn.send("hello world")
-
-
-
conn.close()
-
1