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