Quix
October 11, 2018, 12:55pm
1
hi,i want to try to host a website with processing but i can’t send file
import processing.net.*;
Server myServer;
PrintWriter test;
void setup() {
size(200, 200);
// Starts a myServer on port 5204
myServer = new Server(this, 5204);
println("ip: " + Server.ip() + ":5204");
test = createWriter("untest.html");
test.println("<html><head></head><body>lolol</body></html>");
test.close();
}
void draw() {
Client client = myServer.available();
if(client != null)
{
client.write(test);
}
}
You could use loadStrings() to convert the file into an array of strings, combine all the parts of the array into one String, and then send that string.
kll
October 11, 2018, 1:46pm
3
first i try like
import processing.net.*;
Server myServer;
int port = 5204;
//PrintWriter test;
void setup() {
size(200, 200);
myServer = new Server(this, port);
println("ip: " + Server.ip() + ":"+port);
// test = createWriter("/data/index.html");
// test.println("<html><head></head><body>lolol</body></html>");
// test.close();
}
void draw() {
Client client = myServer.available();
if(client != null)
{
client.write(":-)");
myServer.disconnect(client);
}
}
and “inspect” the result,
as all i write is wrapped in a html page and inside
<pre>:-)</pre>
i could not send any further “html code”
Quix
October 11, 2018, 2:26pm
4
Quillbert1:
loadStrings()
i can’t open it with chrome
I know that works if you just use processing, but i don’t know how you would do that with chrome.
kll
October 11, 2018, 3:34pm
6
here same,
firefox works, chrome not
Quix
October 11, 2018, 5:48pm
7
how can i send uft-8 string?
Quix
October 11, 2018, 5:56pm
8
i put “println(client.read());”
and i find this
GET / HTTP/1.1
Host: 192.168.0.20:5204
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding: gzip, deflate
Accept-Language: fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7
Quix
October 11, 2018, 6:16pm
9
wow now it’s a blank page
Quix
October 12, 2018, 6:32pm
10
yay this code work
import processing.net.*;
Server myServer;
PrintWriter test;
void setup() {
size(200, 200);
// Starts a myServer on port 5204
myServer = new Server(this, 5204);
println("ip: " + Server.ip() + ":5204");
}
void draw() {
Client client = myServer.available();
if(client != null)
{
println(client.readString());
println("-------------------------------");
println(client.ip());
client.write("HTTP/1.1 200 OK\r\n");
client.write("Content-Length: 124\r\n");
client.write("Content-Type: text/html\r\n\r\n");
client.write("<html><head><title>a title</title></head><body><h2>Hi!</h2></body></html>");
client.stop();
}
}
kll
October 13, 2018, 2:04am
11
should not the 124 in
client.write("Content-Length: 124\r\n");
match the chars in
client.write("<html><head><title>a title</title></head><body><h2>Hi!</h2></body></html>");
? CHROME / inspect / console / ERROR
so i use this
not only ( make and ) send a /data/index.html file,
also can send a /data/favicon.ico file