# Tasks

### Python Client & Server

#### Server

```python
import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

port = 12345
host = "127.0.0.1"

s.bind ((host,port))

s.listen(5)

print "Listening..."

while True:

    conn, addr = s.accept()
    print 'Connection from:', addr

    file_name = conn.recv(1024)
    file_name = file_name.strip("\n")
    print "File name:", file_name

    data = conn.recv(2048)
    print "Data Received. "

    file_tmp = open(file_name, "w")
    file_tmp.write(data)
    file_tmp.close()

    print "File created!"
    conn.close
```

#### Client

```python
import socket, sys

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

port = 12345
host = "127.0.0.1"

s.connect((host,port))

file_name = sys.argv[1]
print "File name:", file_name

file_content = sys.argv[2]

s.send(file_name)
print "Send filename."

f = open(file_content, "r")
data = f.read()
s.send(data)
print "Send data."

f.close()
s.close()
print 'uploaded!'
```

### Web Application

#### HTML

```markup
<html>

<head>
    <title> Simple Login Page </title>
</head>

<body>

    <h1> HTML Forms </h1>

    <form method="post" action="login.php">
        Username: <input type="text" name="username"> <br>
        Password: <input type="password" name="password"> <br><br>
        <input type="submit" value="Login">
    </form>

    <p> If you click the "Login" button, the form-data will be sent to a page called "login.php" </p>

</body>

</html>
```

#### PHP

```php
<?php

$username = $_POST["username"];
$password = $_POST["password"];

$credentials = array("user1:passwd1", "user2:passwd2", "user3:passwd3");

foreach ($credentials as $credential) {

    $cred_user = explode(":", $credential)[0];
    $cred_pass = explode(":", $credential)[1];

    if ($username == $cred_user && $password == $cred_pass) {
        echo "You have logged in successfully";
        exit();
    }
}

echo "Login failed, please try again.";

?>
```


---

# Agent Instructions: 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://hsaad.gitbook.io/x/technology-essentials/programming/tasks.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.
