From eae2ceb3ebaf9b934e3c16a9b83023aa110b3440 Mon Sep 17 00:00:00 2001 From: Linloir <3145078758@qq.com> Date: Sun, 9 Oct 2022 21:15:52 +0800 Subject: [PATCH] Change database directory & add readme --- .gitignore | 1 + README.md | 24 ++++++++++++++++++++++-- lib/database.dart | 9 +++++---- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 7b9ba80..54405dc 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ .packages .tmp/ +.data/ .data/** # Conventional directory for build output. diff --git a/README.md b/README.md index 3816eca..708f431 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,22 @@ -A sample command-line application with an entrypoint in `bin/`, library code -in `lib/`, and example unit test in `test/`. +# Simple TCP Server + +This is ~~a project of my Computer Internet course~~ a project inspired by my school homework. + +Several days before I'm asked to write a project on TCP server-client communication, and I wondered why not build a simple chat service beyond that which would be much more fun? + +Therefore here it is, a simple tcp server with several functions which makes it acts like a small chat app. + +## Functions + +- User register / login / logout +- Remember login state for device (simple token approach though) +- Send messages via users +- Search users and add contacts (and accept them of course) +- Message sync via different devices +- Send message to offline server (a SMTP-like approach) +- File handling (transfer to and fetch from server) + +## Notice + +- To support multilanguage, use `base64Encode(utf8.encode(yourMessageHere))` before wrapping client messages in json object and sending that to the server (the serve will crash!) +- Always open a new TCP connection to fetch or send file diff --git a/lib/database.dart b/lib/database.dart index e49df33..2ee4c11 100644 --- a/lib/database.dart +++ b/lib/database.dart @@ -1,7 +1,7 @@ /* * @Author : Linloir * @Date : 2022-10-06 16:15:01 - * @LastEditTime : 2022-10-09 20:28:49 + * @LastEditTime : 2022-10-09 20:31:23 * @Description : */ @@ -25,12 +25,12 @@ class DataBaseHelper { Future initialize() async { _database = await databaseFactoryFfi.openDatabase( - 'E:\\database.db', + '${Directory.current.path}/.tmp/database.db', options: OpenDatabaseOptions( version: 1, - onCreate: (db, version) { + onCreate: (db, version) async { print('[L] Creating Database.'); - db.execute( + await db.execute( ''' CREATE TABLE users ( userid integer primary key autoincrement, @@ -77,6 +77,7 @@ class DataBaseHelper { ); ''' ); + print('[L] Database created'); }, ) );