|
@@ -1,11 +1,14 @@
|
|
|
# Client-Server Protocol
|
|
|
|
|
|
-Protocol version: "0.1"
|
|
|
+Protocol version: <b>"0.2"</b>
|
|
|
+
|
|
|
+Every json message must be minimized and be followed by a newline. This rule makes receiving and parsing the messages easier because you can read until a newline comes and you will parse every json message seperately because you won't read multiple json messages from the buffer at a time.
|
|
|
|
|
|
## 1. Start a connection
|
|
|
|
|
|
-To start a connection you have to check the versions and verify the login.
|
|
|
+To start a connection you have to check the versions and verify the login or signup.
|
|
|
Only if step 1.1 and 1.2 have been accomplished a usable connection is negotiated.
|
|
|
+You can close the connection by sending a cancel message.
|
|
|
|
|
|
### 1.1 Version check
|
|
|
Client:
|
|
@@ -26,23 +29,66 @@ Server:
|
|
|
|
|
|
If `accept` is `true` the connection is valid. Else the connection will be terminated after the server answered.
|
|
|
|
|
|
-### 1.2 Login
|
|
|
+
|
|
|
+## 1.2 Login / Signup
|
|
|
+
|
|
|
+The client is supposed to always send every field used for the login requests: `login`, `user`, `pass` and `cancel`.
|
|
|
+The server is supposed to always send every field used for the login answer: `accept` and `error`.
|
|
|
+
|
|
|
+### 1.2.1 Login
|
|
|
Client:
|
|
|
```
|
|
|
{
|
|
|
+ "login": true,
|
|
|
"user": string,
|
|
|
- "pass": string
|
|
|
+ "pass": string,
|
|
|
+ "cancel": false
|
|
|
}
|
|
|
```
|
|
|
|
|
|
Server:
|
|
|
```
|
|
|
{
|
|
|
- "accept": bool
|
|
|
+ "accept": bool,
|
|
|
+ "error": string
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+If `accept` is `true` the connection is valid and the user is logged in. Else `error` has an error string and the connection will be terminated after the server answered.
|
|
|
+
|
|
|
+### 1.2.2 Signup
|
|
|
+Client:
|
|
|
+```
|
|
|
+{
|
|
|
+ "login": false,
|
|
|
+ "user": string,
|
|
|
+ "pass": string,
|
|
|
+ "cancel": false
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+Server:
|
|
|
+```
|
|
|
+{
|
|
|
+ "accept": bool,
|
|
|
+ "error": string
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+If `accept` is `true` the connection is valid and the user is logged in and signed up. Else `error` has an error string and the connection will be terminated after the server answered.
|
|
|
+
|
|
|
+### 1.2.3 Cancel login
|
|
|
+Client:
|
|
|
+```
|
|
|
+{
|
|
|
+ "login": bool,
|
|
|
+ "user": string,
|
|
|
+ "pass": string,
|
|
|
+ "cancel": true
|
|
|
}
|
|
|
```
|
|
|
|
|
|
-If `accept` is `true` the connection is valid and the user is logged in. Else the connection will be terminated after the server answered.
|
|
|
+After the cancel message was sent the connection will be closed.
|
|
|
|
|
|
|
|
|
## 2. Sending commands
|
|
@@ -67,31 +113,60 @@ Server:
|
|
|
```
|
|
|
|
|
|
### 2.2 List command
|
|
|
+List is split in two commands. `list` to request a list download and `listdata` to download the list.
|
|
|
+
|
|
|
+#### 2.2.1 list - request file list download
|
|
|
Client:
|
|
|
```
|
|
|
{
|
|
|
"command": "list"
|
|
|
}
|
|
|
```
|
|
|
+Server:
|
|
|
+```
|
|
|
+{
|
|
|
+ "command": "list",
|
|
|
+ "accept": bool,
|
|
|
+ "items": int,
|
|
|
+ "chunks": int,
|
|
|
+ "error": string
|
|
|
+}
|
|
|
+```
|
|
|
|
|
|
+#### 2.2.2 listdata - download file list
|
|
|
+Client:
|
|
|
+```
|
|
|
+{
|
|
|
+ "command": "listdata",
|
|
|
+ "chunk": int,
|
|
|
+ "cancel": bool
|
|
|
+}
|
|
|
+```
|
|
|
Server:
|
|
|
```
|
|
|
{
|
|
|
- "command": "put",
|
|
|
+ "command": "listdata",
|
|
|
+ "remaining": int,
|
|
|
+ "cancel": bool,
|
|
|
"names": string[],
|
|
|
- "remaining": int
|
|
|
+ "error": string
|
|
|
}
|
|
|
```
|
|
|
-The server loops this until all names have been sent and `remaining` hits `0`.
|
|
|
+The client has to request every chunk until all names have been sent and `remaining` hits `0`.
|
|
|
|
|
|
|
|
|
### 2.3 Put command
|
|
|
+
|
|
|
+Put is split in two commands. `put` to request a file upload and `putdata` to upload the data.
|
|
|
+
|
|
|
+#### 2.3.1 put - request upload
|
|
|
Client:
|
|
|
```
|
|
|
{
|
|
|
"command": "put",
|
|
|
"file": string,
|
|
|
- "size": int
|
|
|
+ "size": int,
|
|
|
+ "chunks": int
|
|
|
}
|
|
|
```
|
|
|
|
|
@@ -99,15 +174,20 @@ Server:
|
|
|
```
|
|
|
{
|
|
|
"command": "put",
|
|
|
- "accept": bool
|
|
|
+ "file": string,
|
|
|
+ "accept": bool,
|
|
|
+ "error": string
|
|
|
}
|
|
|
```
|
|
|
-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.
|
|
|
-<br /><br />
|
|
|
+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. `error` should contain an error string if the request was rejected.
|
|
|
+
|
|
|
+
|
|
|
+#### 2.3.2 putdata - upload data
|
|
|
Client:
|
|
|
```
|
|
|
{
|
|
|
- "command": "put",
|
|
|
+ "command": "putdata",
|
|
|
+ "file": string,
|
|
|
"data": string,
|
|
|
"remaining": int,
|
|
|
"cancel": bool
|
|
@@ -120,14 +200,21 @@ If `cancel` is `true` the file transfer will be canceled.
|
|
|
Server:
|
|
|
```
|
|
|
{
|
|
|
- "command": "put",
|
|
|
+ "command": "putdata",
|
|
|
+ "file": string,
|
|
|
"recieved": int,
|
|
|
- "cancel": bool
|
|
|
+ "cancel": bool,
|
|
|
+ "error": string
|
|
|
}
|
|
|
```
|
|
|
-If `cancel` is `false` then cancel the upload of the file.
|
|
|
+If `cancel` is `true` then the upload of the file is canceled and an error message should be in `error`.
|
|
|
|
|
|
### 2.4 Get command
|
|
|
+
|
|
|
+Get is split in two commands. `get` to request a file download and `getdata` to download the data.
|
|
|
+
|
|
|
+#### 2.4.1 get - request download
|
|
|
+
|
|
|
Client:
|
|
|
```
|
|
|
{
|
|
@@ -140,33 +227,42 @@ Server:
|
|
|
```
|
|
|
{
|
|
|
"command": "get",
|
|
|
- "accept": bool
|
|
|
+ "file": string,
|
|
|
+ "accept": bool,
|
|
|
+ "chunks": int,
|
|
|
+ "error": string
|
|
|
}
|
|
|
```
|
|
|
-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.
|
|
|
-<br /><br />
|
|
|
-Server:
|
|
|
+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. `error` should contain an error string if the request was rejected. `chunks` is the number of chunks of the file.
|
|
|
+
|
|
|
+#### 2.4.2 getdata - download data
|
|
|
+
|
|
|
+Client:
|
|
|
```
|
|
|
{
|
|
|
- "command": "get",
|
|
|
- "data": string,
|
|
|
- "remaining": int,
|
|
|
+ "command": "getdata",
|
|
|
+ "file": string,
|
|
|
+ "chunk": 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.
|
|
|
+If `cancel` is `true` then cancel the download of the file.
|
|
|
<br /><br />
|
|
|
-Client:
|
|
|
+Server:
|
|
|
```
|
|
|
{
|
|
|
- "command": "get",
|
|
|
- "recieved": int,
|
|
|
- "cancel": bool
|
|
|
+ "command": "getdata",
|
|
|
+ "file": string,
|
|
|
+ "data": string,
|
|
|
+ "remaining": int,
|
|
|
+ "cancel": bool,
|
|
|
+ "error": string
|
|
|
}
|
|
|
```
|
|
|
-If `cancel` is `false` then cancel the download of the file.
|
|
|
+`data` is a base64 string and contains a piece of the file. The client must request every chunk.
|
|
|
+`remaining` is a counter how many chunks will follow and the transfer is over after it hits `0`.
|
|
|
+If `cancel` is `true` then the download of the file is canceled and an error message should be in `error`.
|
|
|
+
|
|
|
|
|
|
### TODO
|
|
|
|