Skip to content

Commit

Permalink
read port from argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Linloir committed Oct 9, 2022
1 parent 3b0dff6 commit af41d6b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ cd Simple-TCP-Server
# mkdir build
# dart compile exe ./bin/tcp_server.dart -o ./build/tcp_server.exe
# cd build
# tcp_server.exe
# tcp_server.exe [listen port]

dart run
```
Expand Down
7 changes: 5 additions & 2 deletions bin/tcp_server.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @Author : Linloir
* @Date : 2022-10-06 15:44:16
* @LastEditTime : 2022-10-09 20:13:17
* @LastEditTime : 2022-10-09 22:57:10
* @Description :
*/

Expand All @@ -15,6 +15,9 @@ import 'package:tcp_server/tcpcontroller/request.dart';
import 'package:tcp_server/tcpcontroller/response.dart';

void main(List<String> arguments) async {
//Set port
var port = arguments.isEmpty ? 20706 : int.tryParse(arguments[0]) ?? 20706;

//Create nessesary working directories
await Directory('${Directory.current.path}/.tmp').create();
await Directory('${Directory.current.path}/.data').create();
Expand All @@ -23,7 +26,7 @@ void main(List<String> arguments) async {
await DataBaseHelper().initialize();
var tokenMap = <int, TCPController>{};
var controllerMap = <TCPController, Future<int>>{};
var listenSocket = await ServerSocket.bind('127.0.0.1', 20706);
var listenSocket = await ServerSocket.bind('127.0.0.1', port);
listenSocket.listen(
(socket) {
var controller = TCPController(socket: socket);
Expand Down
3 changes: 1 addition & 2 deletions lib/tcpcontroller/request.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/*
* @Author : Linloir
* @Date : 2022-10-08 15:14:26
* @LastEditTime : 2022-10-09 17:36:42
* @LastEditTime : 2022-10-09 22:56:26
* @Description :
*/
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';

enum RequestType {
checkState ('STATE'), //Check login state for device token
Expand Down

0 comments on commit af41d6b

Please sign in to comment.