Sending javascript touch events to Processing
in
Core Library Questions
•
2 years ago
Hi!
My overall goal is to be able to allow someone with a touchscreen device (iPhone, for example) to be able to connect to a website running javascript, and for their touch coordinates (x, y) to be sent to a Processing sketch. I know that if I can get the below working (sending 'hi' from a .js client to a Processing server), that I will be set.
My current approach is to run a server in the Processing sketch and try to send data via Javascript. However, the output is a little off (shown below). Any ideas or suggestions are greatly appreciated.
The javascript (it uses http://socket.io/):
The Processing (an example straight from Processing.org):
The resulting output server-side:
My overall goal is to be able to allow someone with a touchscreen device (iPhone, for example) to be able to connect to a website running javascript, and for their touch coordinates (x, y) to be sent to a Processing sketch. I know that if I can get the below working (sending 'hi' from a .js client to a Processing server), that I will be set.
My current approach is to run a server in the Processing sketch and try to send data via Javascript. However, the output is a little off (shown below). Any ideas or suggestions are greatly appreciated.
The javascript (it uses http://socket.io/):
- <script src="http://cdn.socket.io/stable/socket.io.js"></script>
<script type="text/javascript">
var socket = new io.Socket('localhost',{
port: 10002
});
socket.connect(); }
socket.send('hi'); - </script>
The Processing (an example straight from Processing.org):
- // Example by Tom Igoe
import processing.net.*;
int port = 10002;
Server myServer;
void setup()
{
size(400, 400);
background(0);
myServer = new Server(this, port);
}
void draw()
{
// Get the next available client
Client thisClient = myServer.available();
// If the client is not null, and says something, display what it said
if (thisClient !=null) {
String whatClientSaid = thisClient.readString();
if (whatClientSaid != null) {
println(thisClient.ip() + "t" + whatClientSaid);
}
}
}
The resulting output server-side:
- 0:0:0:0:0:0:0:1tGET /socket.io/xhr-multipart/ HTTP/1.1
Host: localhost:10002
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Origin: null
Pragma: no-cache
Cache-Control: no-cache
1