Protocol version: "0.2"
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.
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.
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.
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
.
Client:
{
"login": true,
"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. Else error
has an error string and the connection will be terminated after the server answered.
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.
Client:
{
"login": bool,
"user": string,
"pass": string,
"cancel": true
}
After the cancel message was sent the connection will be closed.
Commands can be sent by the client after a connection has been negotiated (See 1). Commands can be used unrelated to each other.
Client:
{
"command": "status"
}
Server:
{
"command": "status",
"response": string
}
List is split in two commands. list
to request a list download and listdata
to download the list.
Client:
{
"command": "list"
}
Server:
{
"command": "list",
"accept": bool,
"items": int,
"chunks": int,
"error": string
}
Client:
{
"command": "listdata",
"chunk": int,
"cancel": bool
}
Server:
{
"command": "listdata",
"remaining": int,
"cancel": bool,
"names": string[],
"error": string
}
The client has to request every chunk until all names have been sent and remaining
hits 0
.
Put is split in two commands. put
to request a file upload and putdata
to upload the data.
Client:
{
"command": "put",
"file": string,
"size": int,
"chunks": int
}
Server:
{
"command": "put",
"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. error
should contain an error string if the request was rejected.
Client:
{
"command": "putdata",
"file": string,
"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": "putdata",
"file": string,
"recieved": int,
"cancel": bool,
"error": string
}
If cancel
is true
then the upload of the file is canceled and an error message should be in error
.
Get is split in two commands. get
to request a file download and getdata
to download the data.
Client:
{
"command": "get",
"file": string
}
Server:
{
"command": "get",
"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. error
should contain an error string if the request was rejected. chunks
is the number of chunks of the file.
Client:
{
"command": "getdata",
"file": string,
"chunk": int,
"cancel": bool
}
If cancel
is true
then cancel the download of the file.
Server:
{
"command": "getdata",
"file": string,
"data": string,
"remaining": int,
"cancel": bool,
"error": string
}
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
.
Client:
{
"command": "close"
}
Server:
{
"command": "close",
"response": "bye"
}