mirror of
https://github.com/fumiama/simple-dict.git
synced 2026-06-05 02:00:25 +08:00
edit README
This commit is contained in:
123
README.md
123
README.md
@@ -1,9 +1,12 @@
|
||||
# simple-dict-server
|
||||
database["key"]="value" with tea encryption.
|
||||
|
||||
# Compile
|
||||
You should first clone this project into a system with cmake & libpthread installed.
|
||||
If you plan to compile it on Windows, you should edit the source code and transform socket/thread/file libraries into Windows version.
|
||||
## Prepare
|
||||
Install [simple-crypto](https://github.com/fumiama/simple-crypto) and [simple-protobuf](https://github.com/fumiama/simple-protobuf) into `/usr/local` according to their README.
|
||||
|
||||
## Compile
|
||||
Clone this project into a system with cmake & libpthread installed.
|
||||
If you plan to compile it on Windows, you ought to edit the source code and transform socket/thread/file libraries into a Windows version.
|
||||
```bash
|
||||
git clone https://github.com/fumiama/simple-dict-server.git
|
||||
```
|
||||
@@ -15,27 +18,30 @@ mkdir build
|
||||
Use `cmake` command to generate files for `make` automatically.
|
||||
```bash
|
||||
cd build
|
||||
cmake ../
|
||||
cmake ..
|
||||
```
|
||||
Use `make` to generate executable binary files named `simple-dict-server` and `simple-dict-client` in `./build` directory.
|
||||
```bash
|
||||
make
|
||||
```
|
||||
Then you should install [simple-crypto](https://github.com/fumiama/simple-crypto) and [simple-protobuf](https://github.com/fumiama/simple-protobuf) by the same way.
|
||||
Optional: Use `make install` to install `simple-dict-server` into `/usr/local/bin`.
|
||||
|
||||
# Execute
|
||||
## Execute
|
||||
Start server on localhost using the commands below.
|
||||
```bash
|
||||
chmod +x simple-dict-server simple-dict-client
|
||||
./simple-dict-server -d 7777 1 ./dict.sp ./cfg.sp # use -d to start as daemon
|
||||
Usage:
|
||||
./simple-dict-server [-d] listen_port dict_file [config_file | -]
|
||||
-d: As daemon
|
||||
- : Read config from env SDS_PWD & SDS_SPS
|
||||
```
|
||||
`cfg.sp`is generated by `cfgwriter`, or you can pass config by setting env `SDS_PWD` and `SDS_SPS`.
|
||||
`cfg.sp`is generated by `cfgwriter`, otherwise you can pass config by setting env `SDS_PWD` and `SDS_SPS`.
|
||||
|
||||
Open another shell to connect to it.
|
||||
```bash
|
||||
./simple-dict-client 127.0.0.1 7777
|
||||
```
|
||||
Now you have connected to the server. The default access passwords is in `client.c` and you can modify the password in source code as you like. Please note that the server will only wait `10` seconds for a response after the last communication. The box below shows how to control the server to accompilsh basic add/del/find/edit operations.
|
||||
Now you have connected to the server. The default access passwords is in `client.c` and you can modify the password in source code as you like. Please note that the server will only wait `4` seconds for a response after the last communication. The box below shows how to control the server to accompilsh basic add/del/find/edit operations.
|
||||
|
||||
| cmd | data | description | reply |
|
||||
| ---- | ---- | ---- | ----- |
|
||||
@@ -51,105 +57,10 @@ Now you have connected to the server. The default access passwords is in `client
|
||||
- Whenever the reply is "erro", it indicates that the server has some troubles, which means that you shuold end the conversation and retry later.
|
||||
|
||||
A cmd sequence example is as below
|
||||
```bash
|
||||
get:test
|
||||
set:test
|
||||
dat:测试
|
||||
get:test
|
||||
del:test
|
||||
get:test
|
||||
end
|
||||
```
|
||||
The client output is
|
||||
```bash
|
||||
break!
|
||||
Get sockfd
|
||||
Connected to server
|
||||
Thread create succeeded
|
||||
Enter command:get:test
|
||||
Send data succeed.
|
||||
recv ack: null
|
||||
Enter command:set:test
|
||||
Send data succeed.
|
||||
recv ack: data
|
||||
Enter command:dat:测试
|
||||
Send data succeed.
|
||||
recv ack: succ
|
||||
Enter command:get:test
|
||||
Send data succeed.
|
||||
recv ack: 测试
|
||||
Enter command:del:test
|
||||
Send data succeed.
|
||||
recv ack: succ
|
||||
Enter command:get:test
|
||||
Send data succeed.
|
||||
recv ack: null
|
||||
Enter command:end
|
||||
Send data succeed.
|
||||
```
|
||||
The server output meanwhile is
|
||||
```bash
|
||||
Bind server success!
|
||||
Listening....
|
||||
Ready for accept, waitting...
|
||||
Next thread is No.0
|
||||
Accept client ::ffff:127.0.0.1:51296
|
||||
Creating thread succeeded
|
||||
Ready for accept, waitting...
|
||||
|
||||
Connected to the client.
|
||||
Next thread is No.1
|
||||
Creating timer thread succeeded
|
||||
Wait sec: 2, max: 10
|
||||
[normal] Get 34 bytes packet with cmd: 0, data: test
|
||||
Close dict
|
||||
Send data: null
|
||||
Wait sec: 0, max: 10
|
||||
Wait sec: 2, max: 10
|
||||
Wait sec: 4, max: 10
|
||||
[super] Get 34 bytes packet with data: test
|
||||
Send data: data
|
||||
Wait sec: 1, max: 10
|
||||
Wait sec: 3, max: 10
|
||||
[super] Get 34 bytes packet with data: 测试
|
||||
Data copy to dict succ
|
||||
Set data: dict[test]=测试
|
||||
Close dict
|
||||
Send data: succ
|
||||
Wait sec: 0, max: 10
|
||||
Wait sec: 2, max: 10
|
||||
[normal] Get 34 bytes packet with cmd: 0, data: test
|
||||
Close dict
|
||||
Send data: 测试
|
||||
Wait sec: 0, max: 10
|
||||
Wait sec: 2, max: 10
|
||||
[super] Get 34 bytes packet with data: test
|
||||
Close dict
|
||||
Send data: succ
|
||||
Wait sec: 0, max: 10
|
||||
Wait sec: 2, max: 10
|
||||
[normal] Get 34 bytes packet with cmd: 0, data: test
|
||||
Close dict
|
||||
Send data: null
|
||||
Wait sec: 0, max: 10
|
||||
[normal] Get 34 bytes packet with cmd: 4, data: fill
|
||||
Conversation end
|
||||
https://user-images.githubusercontent.com/41315874/163713542-5d8c6eda-2ff4-4a09-8a0e-8865292c0022.mp4
|
||||
|
||||
Start killing.
|
||||
Close accept.
|
||||
Free data.
|
||||
Close dict
|
||||
Finish killing.
|
||||
Wait sec: 0, max: 10
|
||||
Call kill thread
|
||||
Start killing.
|
||||
Close dict
|
||||
Finish killing.
|
||||
Free timer
|
||||
Finish calling kill thread
|
||||
```
|
||||
|
||||
# Android Client for simple-dict-server
|
||||
## Android Client for simple-dict-server
|
||||
There is also an [Android Client](https://github.com/fumiama/simple-dict-android) for simple-dict-server. Just install the apk file downloaded from release page and click `config` icon to set your server address using the format
|
||||
```
|
||||
127.0.0.1:7777_password
|
||||
|
||||
7
client.c
7
client.c
@@ -107,12 +107,7 @@ void getMessage(void *p) {
|
||||
#ifdef DEBUG
|
||||
printf("[normal] Get %u bytes packet with data: %s\n", offset, cp->data);
|
||||
#endif
|
||||
switch(cp->cmd) {
|
||||
case CMDACK:
|
||||
printf("recv ack: %s\n", cp->data);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
printf("[%d] recv ack: %s\n", (int)cp->cmd, cp->data);
|
||||
}
|
||||
if(offset > c) {
|
||||
offset -= c;
|
||||
|
||||
Reference in New Issue
Block a user