# Client-Server Protocol
Protocol version: "0.1"
## 1. Start a connection
To start a connection you have to check the versions and verify the login.
Only if step 1.1 and 1.2 have been accomplished a usable connection is negotiated.
### 1.1 Version check
Client:
```
{
"version": string
}
```
Server:
```
{
"version": string,
"accept": bool
}
```
If `accept` is `true` the connection is valid. Else the connection will be terminated after the server answered.
### 1.2 Login
Client:
```
{
"user": string,
"pass": string
}
```
Server:
```
{
"accept": bool
}
```
If `accept` is `true` the connection is valid and the user is logged in. Else the connection will be terminated after the server answered.
## 2. Sending commands
Commands can be sent by the client after a connection has been negotiated (See 1).
Commands can be used unrelated to each other.
### 2.1 Status command
Client:
```
{
"command": "status"
}
```
Server:
```
{
"command": "status",
"response": string
}
```
### 2.2 List command
Client:
```
{
"command": "list"
}
```
Server:
```
{
"command": "put",
"names": string[],
"remaining": int
}
```
The server loops this until all names have been sent and `remaining` hits `0`.
### 2.3 Put command
Client:
```
{
"command": "put",
"file": string,
"size": int
}
```
Server:
```
{
"command": "put",
"accept": bool
}
```
If `accept` is `true` the connection is valid and the client can start sending the file. Else the put request was rejected and is hereby canceled.
Client:
```
{
"command": "put",
"data": string,
"remaining": int,
"cancel": bool
}
```
`data` is a base64 string and contains a piece of the file. The client will loop this until the file is completely sent and the server has to send and received message for every chunk.
`remaining` is a counter how many chunks will follow and the transfer is over after it hits `0`.
If `cancel` is `true` the file transfer will be canceled.
Server:
```
{
"command": "put",
"recieved": int,
"cancel": bool
}
```
If `cancel` is `false` then cancel the upload of the file.
### 2.4 Get command
Client:
```
{
"command": "get",
"file": string
}
```
Server:
```
{
"command": "get",
"accept": bool
}
```
If `accept` is `true` the connection is valid and the server can start sending the file. Else the get request was rejected and is hereby canceled.
Server:
```
{
"command": "get",
"data": string,
"remaining": int,
"cancel": bool
}
```
`data` is a base64 string and contains a piece of the file. The server will loop this until the file is completely sent and the client has to send a received message for every chunk.
`remaining` is a counter how many chunks will follow and the transfer is over after it hits `0`.
If `cancel` is `true` the file transfer will be canceled.
Client:
```
{
"command": "get",
"recieved": int,
"cancel": bool
}
```
If `cancel` is `false` then cancel the download of the file.
### TODO
## 3. Close connection
### 3.1 Close command
Client:
```
{
"command": "close"
}
```
Server:
```
{
"command": "close",
"response": "bye"
}
```