Use other sockets with Processing network client

I have written a game server in Python (it’s more fit for the job, with async and all). Now I’m working to integrate its functionality with Processing. I’m using Client from processing.net.*

Here’s an example of my issue:
(Python)

from socket import socket
a = socket()
a.bind(('0.0.0.0', 9050))
a.listen(1)
b, c = a.accept()  # accepts connection from processing client
print(b.recv(1024).decode()) # so far so good, prints out -> gday
b.send(b'hello there')

(Processing)

import processing.net.*;

Client client;

void setup() {
    client = new Client(this, "127.0.0.1", 9050); // Connects to python server
    client.write("hello");  // so far so good
}

void clientEvent(Client client) {
    String in = client.readString();  // problem! program quits with error
    println(in);
}

(Error, from Processing)

Receiving:h
error, disabling clientEvent() for 127.0.0.1
java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at processing.net.Client.run(Unknown Source)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
	at server.clientEvent(server.java:49)
	... 6 more

Here’s the full story.

I’m stupid.

1 Like

I’m curious (And I bet people in the future will be as well)

It’s important to note that the error displayed is slightly misleading.
When it says

error, disabling clientEvent() for 127.0.0.1

It is merely displaying a symptom of the actual issue. In fact, the actual issue was entirely unrelated to networking. The lesson to be learned is to notice the trace a few lines down.

Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
	at server.clientEvent(server.java:49)

I fixed that issue.

2 Likes