# How can i send a file with server.write?

**URL:** https://discourse.processing.org/t/how-can-i-send-a-file-with-server-write/4360
**Category:** Libraries
**Created:** [October 11, 2018, 12:55pm UTC](https://discourse.processing.org/t/how-can-i-send-a-file-with-server-write/4360 "2018-10-11T12:55:51Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Quix](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quix/32/2011_2.png) [@Quix](https://discourse.processing.org/u/Quix)
#### Post date: [October 11, 2018, 12:55pm UTC](https://discourse.processing.org/t/how-can-i-send-a-file-with-server-write/4360/1 "2018-10-11T12:55:51Z")

</div>

hi,i want to try to host a website with processing but i can’t send file

```auto
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);
  }
}

```

---

<div class="post-metadata">

### Author: ![Quillbert1](https://avatars.discourse-cdn.com/v4/letter/q/f475e1/32.png) [@Quillbert1](https://discourse.processing.org/u/Quillbert1)
#### Post date: [October 11, 2018, 1:07pm UTC](https://discourse.processing.org/t/how-can-i-send-a-file-with-server-write/4360/2 "2018-10-11T13:07:44Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [October 11, 2018, 1:46pm UTC](https://discourse.processing.org/t/how-can-i-send-a-file-with-server-write/4360/3 "2018-10-11T13:46:46Z")

</div>

first i try like

```auto
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

```auto
<pre>:-)</pre>

```

i could not send any further “html code”

 ![snap-037](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/0e15f3d4a20e955d97a25855a9a992b091cf8ce9.jpeg)

---

<div class="post-metadata">

### Author: ![Quix](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quix/32/2011_2.png) [@Quix](https://discourse.processing.org/u/Quix)
#### Post date: [October 11, 2018, 2:26pm UTC](https://discourse.processing.org/t/how-can-i-send-a-file-with-server-write/4360/4 "2018-10-11T14:26:43Z")

</div>

> [@Quillbert1](#):
>
> loadStrings()

i can’t open it with chrome

---

<div class="post-metadata">

### Author: ![Quillbert1](https://avatars.discourse-cdn.com/v4/letter/q/f475e1/32.png) [@Quillbert1](https://discourse.processing.org/u/Quillbert1)
#### Post date: [October 11, 2018, 3:01pm UTC](https://discourse.processing.org/t/how-can-i-send-a-file-with-server-write/4360/5 "2018-10-11T15:01:46Z")

</div>

I know that works if you just use processing, but i don’t know how you would do that with chrome.

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [October 11, 2018, 3:34pm UTC](https://discourse.processing.org/t/how-can-i-send-a-file-with-server-write/4360/6 "2018-10-11T15:34:01Z")

</div>

here same,  
firefox works, chrome not

 ![snap-038](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/7cfc4bdc055a20a035d1d6f58e59823ec9659c06.jpeg)

---

<div class="post-metadata">

### Author: ![Quix](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quix/32/2011_2.png) [@Quix](https://discourse.processing.org/u/Quix)
#### Post date: [October 11, 2018, 5:48pm UTC](https://discourse.processing.org/t/how-can-i-send-a-file-with-server-write/4360/7 "2018-10-11T17:48:21Z")

</div>

how can i send uft-8 string?

---

<div class="post-metadata">

### Author: ![Quix](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quix/32/2011_2.png) [@Quix](https://discourse.processing.org/u/Quix)
#### Post date: [October 11, 2018, 5:56pm UTC](https://discourse.processing.org/t/how-can-i-send-a-file-with-server-write/4360/8 "2018-10-11T17:56:30Z")

</div>

i put “println(client.read());”  
and i find this

```auto
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

```

---

<div class="post-metadata">

### Author: ![Quix](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quix/32/2011_2.png) [@Quix](https://discourse.processing.org/u/Quix)
#### Post date: [October 11, 2018, 6:16pm UTC](https://discourse.processing.org/t/how-can-i-send-a-file-with-server-write/4360/9 "2018-10-11T18:16:08Z")

</div>

wow now it’s a blank page ![screen](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/b/bdebf0fccb6aae068a35ae326b3fcecace46a4b8.png)

---

<div class="post-metadata">

### Author: ![Quix](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quix/32/2011_2.png) [@Quix](https://discourse.processing.org/u/Quix)
#### Post date: [October 12, 2018, 6:32pm UTC](https://discourse.processing.org/t/how-can-i-send-a-file-with-server-write/4360/10 "2018-10-12T18:32:55Z")

</div>

yay this code work 🙂

```auto
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();
  }
}

```

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [October 13, 2018, 2:04am UTC](https://discourse.processing.org/t/how-can-i-send-a-file-with-server-write/4360/11 "2018-10-13T02:04:06Z")

</div>

should not the 124 in

```auto
client.write("Content-Length: 124\r\n");

```

match the chars in

```auto
client.write("<html><head><title>a title</title></head><body><h2>Hi!</h2></body></html>");

```

? CHROME / inspect / console / ERROR

so i use [this](http://kll.engineering-news.org/kllfusion01/downloads/processing_webserver.pde.txt)  
not only ( make and ) send a **/data/index.html** file,  
also can send a **/data/favicon.ico** file
