> For the complete documentation index, see [llms.txt](https://lifelong-learning.gitbook.io/pythonjourney/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lifelong-learning.gitbook.io/pythonjourney/diary-project/web_programming.md).

# Diary-web-programming

### Task description

* Build onlien diary program
  * Use your own computer as server and client to write diary.
  * Server has the diary file, and respond to client requests.
  * Client can read, write diary through requests.

### Input

* Client send request to write or quit.
* As aboved, the diary content display once the client connects to the server.

### Output

* Once the program start, automately display diary content
* When user send a line of text, save it automately.
* When user ask to quit, exit. &#x20;

### Difficulties

* TCP/IP, socket concept

### Neglected Details

* The server can send bytes, which should be converted to string in client, vice versa.-string to bytes: `.encode()`,bytes to string: `.decode()`
* Use Enter to quit can't work in server, so change it to 'Q'.

### Materials:

* [TCP/IP socket course in chinese](https://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/001386832511628f1fe2c65534a46aa86b8e654b6d3567c000)
* [Brief example of socket](https://pythontips.com/2013/08/06/python-socket-network-programming/)

## Code

[Github Code Link for server](https://github.com/ShakalakaB/Python_journey_code/blob/master/diary-project/diary_server.py) [Github Code Link for client](https://github.com/ShakalakaB/Python_journey_code/blob/master/diary-project/diary_client.py)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lifelong-learning.gitbook.io/pythonjourney/diary-project/web_programming.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
