network lib and http get request
in
Core Library Questions
•
3 years ago
hello everyone. i'm trying to set up a web interface to control my processing sketch. i'd like to load content from the processing sketch and insert it in my html.
so i started with a simple javascript which performs a http get request (jquery) and the chat server example to read it. it works fine, which means the request shows up in my processing sketch. but when i try to reply the request by calling the myServer.write() function the jquery alert box doesnt show the content of my message. at least it shows up which means it somehow reacts on my message.
how do i have to format the reply? or am i getting sth completely wrong? would be glad if someone could help.
this is my small jquery code which is running on a apache webserver (same pc as the processing sketch):
and this is a part of the processing sketch code, basicly the chat server example:
and to complete it: the reply.txt - i tried different versions, but jet no success
so i started with a simple javascript which performs a http get request (jquery) and the chat server example to read it. it works fine, which means the request shows up in my processing sketch. but when i try to reply the request by calling the myServer.write() function the jquery alert box doesnt show the content of my message. at least it shows up which means it somehow reacts on my message.
how do i have to format the reply? or am i getting sth completely wrong? would be glad if someone could help.
this is my small jquery code which is running on a apache webserver (same pc as the processing sketch):
- $(document).ready(function(){
- loadPage();
- });
- function loadPage(url) {
- $.get('http://myURL:10002',{}, function(data) {
- alert('Load was performed.' + data);
- });
- }
and this is a part of the processing sketch code, basicly the chat server example:
- void draw(){
- if (myServerRunning == true){
- Client thisClient = myServer.available();
- if (thisClient != null){
- if (thisClient.available() > 0) {
- println(thisClient.readString());
- println();
- String reply = "";
- String lines[] = loadStrings("data/reply.txt");
- for (int i=0; i<lines.length; i++){
- reply += lines[i];
- reply += "\r\n";
- }
- myServer.write(reply);
- println(reply);
- }
- }
- }
- else
- {
- text("server", 15, 45);
- text("stopped", 15, 65);
- }
- }
and to complete it: the reply.txt - i tried different versions, but jet no success
- HTTP/1.1 200 OK
- Content-Type: text/plain
- Content-Length: 10
- 1234567890
1