mirror of
https://github.com/Linloir/Simple-TCP-Server.git
synced 2025-12-16 23:48:11 +08:00
Behavior update:
- Push contact info to client when adding contact - Prevent crash when add bytes to closed request stream
This commit is contained in:
parent
325e518a17
commit
8627538d31
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author : Linloir
|
||||
* @Date : 2022-10-06 15:44:16
|
||||
* @LastEditTime : 2022-10-20 10:47:50
|
||||
* @LastEditTime : 2022-10-20 16:34:10
|
||||
* @Description :
|
||||
*/
|
||||
|
||||
@ -200,6 +200,15 @@ void main(List<String> arguments) async {
|
||||
case RequestType.addContact: {
|
||||
var response = await onAddContact(request, socket);
|
||||
controller.outStream.add(response);
|
||||
var contactResponse = await onFetchContact(
|
||||
TCPRequest.fromData(
|
||||
type: RequestType.fetchContact,
|
||||
body: {},
|
||||
tokenID: request.tokenID
|
||||
),
|
||||
socket
|
||||
);
|
||||
controller.outStream.add(contactResponse);
|
||||
break;
|
||||
}
|
||||
case RequestType.fetchContact: {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author : Linloir
|
||||
* @Date : 2022-10-06 16:15:01
|
||||
* @LastEditTime : 2022-10-20 10:40:50
|
||||
* @LastEditTime : 2022-10-20 13:14:40
|
||||
* @Description :
|
||||
*/
|
||||
|
||||
@ -617,6 +617,10 @@ class DataBaseHelper {
|
||||
'username': userInfo.userName,
|
||||
'avatar': userInfo.userAvatar
|
||||
},
|
||||
where: 'userid = ?',
|
||||
whereArgs: [
|
||||
currentUserID
|
||||
],
|
||||
conflictAlgorithm: ConflictAlgorithm.rollback
|
||||
);
|
||||
} catch (conflict) {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author : Linloir
|
||||
* @Date : 2022-10-08 15:10:04
|
||||
* @LastEditTime : 2022-10-19 10:41:12
|
||||
* @LastEditTime : 2022-10-20 17:33:52
|
||||
* @Description :
|
||||
*/
|
||||
|
||||
@ -90,7 +90,8 @@ class TCPController {
|
||||
await socket.addStream(response.stream);
|
||||
}
|
||||
} catch (e) {
|
||||
print(e);
|
||||
print('[E] [EXCEPTION]-----------------------');
|
||||
print('[E] Adding bytes to socket stream failed');
|
||||
await socket.flush();
|
||||
socket.close();
|
||||
}
|
||||
@ -201,6 +202,11 @@ class TCPController {
|
||||
required List<int> requestBytes,
|
||||
required File tempFile
|
||||
}) async {
|
||||
_requestStreamController.add(TCPRequest(requestBytes, tempFile));
|
||||
try{
|
||||
_requestStreamController.add(TCPRequest(requestBytes, tempFile));
|
||||
} catch (e) {
|
||||
print('[E] [EXCEPTION]-----------------------');
|
||||
print('[E] Adding bytes to request stream failed');
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author : Linloir
|
||||
* @Date : 2022-10-08 15:14:26
|
||||
* @LastEditTime : 2022-10-09 22:56:26
|
||||
* @LastEditTime : 2022-10-20 16:33:16
|
||||
* @Description :
|
||||
*/
|
||||
import 'dart:convert';
|
||||
@ -40,6 +40,16 @@ class TCPRequest {
|
||||
File? payload;
|
||||
|
||||
TCPRequest(List<int> data, this.payload): _data = jsonDecode(String.fromCharCodes(data));
|
||||
TCPRequest.fromData({
|
||||
required RequestType type,
|
||||
required Map<String, Object?> body,
|
||||
required int? tokenID,
|
||||
this.payload
|
||||
}): _data = {
|
||||
'request': type.value,
|
||||
'tokenid': tokenID,
|
||||
'body': body
|
||||
};
|
||||
TCPRequest.none(): _data = {};
|
||||
|
||||
String get toJSON => jsonEncode(_data);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user